Sponsored Content
Homework and Emergencies Homework & Coursework Questions Need help with a Perl Script using Pop, Shift, & Push Post 302707347 by Corona688 on Friday 28th of September 2012 11:37:12 AM
Old 09-28-2012
You already know how a for-loop works, it seems; the top 5 would just be another loop, from 0 to 5.

As for shuffling the cards, how does one usually shuffle a deck? Split it in half, then combine them randomly. I might try popping each card from the deck individually and putting them in either array A or B. Then looping until array A and B are both empty, popping a card from either A or B each loop and pushing it back into the original array. You could randomly choose which array you pick from.
This User Gave Thanks to Corona688 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

shift and push question in perl

hi, another perl question, I don't understand the below while (<FILE>) { push @last5, $_; #add to the end shift @last5 if @last5 > 5 ; #take from the beginning } can someone please explain to me how does shift @last5 if @last5 > 5 is taking last 5 lines from... (5 Replies)
Discussion started by: hankooknara
5 Replies

2. Shell Programming and Scripting

search & replace password perl script

I wanted a perl script to be done for Password search & replace in two files. For Example: Example 1)--i am having a file such as cat /opt/customer/Ariba/UAT/ariba/app/buyer/Server/config/Parameters.table Example 2)--and i am having a other file in other location such as cat... (4 Replies)
Discussion started by: shellscript22
4 Replies

3. Shell Programming and Scripting

Perl - if conditions is meet, push the last field of $_ into an array

I am using a seed file shown below to separate cisco devices by ios/os type. I want to bunch all the devices based on ios/os version. Once I find a match, I only want to push the ip address into the appropriate array. Example of seedfile 8 host1 (C3500XL-C3H2S-M) 11.0(5)WC17 10.1.44.21 9... (1 Reply)
Discussion started by: popeye
1 Replies

4. Shell Programming and Scripting

Shift Question (Perl)

I am attempting to write a script that reads each line of a file into a separate array and does some work on it then puts it all back together and I think I need to use the 'shift()' command to read each line into its own array, but I need help nesting it into a while loop (while not eof) So... (10 Replies)
Discussion started by: ifeatu
10 Replies

5. Shell Programming and Scripting

PERL, push to hash of array problem

$key = "a"; $value = "hello"; %myhash = {} ; push @{ myHash{$key} }, $hello; print $myHash{$key}."\n"; this script prints "hello" but has following error message. Reference found where even-sized list expected at ./test line 5. can any one help me to fix this problem?? (3 Replies)
Discussion started by: bonosungho
3 Replies

6. Shell Programming and Scripting

push and pop directories and subdirectories

I need to use pushd and popd to navigate all of the subdirectories in my current directory. I know how to get into each subdirectory, add it to the stack, and pop back out, but i cant figure out how to get into subdirectories deeper than the first without adding a foreach and if statement for... (1 Reply)
Discussion started by: ollie88r
1 Replies

7. UNIX for Dummies Questions & Answers

Setup a push script from NIS

Hi guys, can we get a pushed script for every NIS client like a policy.? I need to set a symbolic links for for every client. Thanks ... (1 Reply)
Discussion started by: pianz
1 Replies

8. Shell Programming and Scripting

Help on a script to push files once a day

Hello! Please I need some help on writing a script to push files from one server to the other once a day, everyday. I know that I can use this script on a crontab to send the files , but I am not sure how to start writing it, the actual script. I could start by declaring some variables: ... (4 Replies)
Discussion started by: fretagi
4 Replies

9. Web Development

Pop up confirmation box / perl cgi

Hi, I need to add confirmation pop up msg box before deleting the record from database, I have added following snippets to my code but its not working for me, your help will be much appreciated : print header; print <<EOF; <script type="text/javascript"> function confirmOk() { return... (0 Replies)
Discussion started by: terrykhatri531
0 Replies

10. Shell Programming and Scripting

Script to Push Files

Hey Guys, Thanks for always being helpful, I have another issue that I need a little insight on how to fix. See the below script I have and the error I get. I don't understand why it does that, am I not using the continue correctly? #!/bin/bash -x # @(#) File: filepush.sh #... (5 Replies)
Discussion started by: gkelly1117
5 Replies
Tie::IxHash(3)						User Contributed Perl Documentation					    Tie::IxHash(3)

NAME
Tie::IxHash - ordered associative arrays for Perl SYNOPSIS
# simple usage use Tie::IxHash; tie HASHVARIABLE, Tie::IxHash [, LIST]; # OO interface with more powerful features use Tie::IxHash; TIEOBJECT = Tie::IxHash->new( [LIST] ); TIEOBJECT->Splice( OFFSET [, LENGTH [, LIST]] ); TIEOBJECT->Push( LIST ); TIEOBJECT->Pop; TIEOBJECT->Shift; TIEOBJECT->Unshift( LIST ); TIEOBJECT->Keys( [LIST] ); TIEOBJECT->Values( [LIST] ); TIEOBJECT->Indices( LIST ); TIEOBJECT->Delete( [LIST] ); TIEOBJECT->Replace( OFFSET, VALUE, [KEY] ); TIEOBJECT->Reorder( LIST ); TIEOBJECT->SortByKey; TIEOBJECT->SortByValue; TIEOBJECT->Length; DESCRIPTION
This Perl module implements Perl hashes that preserve the order in which the hash elements were added. The order is not affected when values corresponding to existing keys in the IxHash are changed. The elements can also be set to any arbitrary supplied order. The familiar perl array operations can also be performed on the IxHash. Standard "TIEHASH" Interface The standard "TIEHASH" mechanism is available. This interface is recommended for simple uses, since the usage is exactly the same as regular Perl hashes after the "tie" is declared. Object Interface This module also provides an extended object-oriented interface that can be used for more powerful operations with the IxHash. The following methods are available: FETCH, STORE, DELETE, EXISTS These standard "TIEHASH" methods mandated by Perl can be used directly. See the "tie" entry in perlfunc(1) for details. Push, Pop, Shift, Unshift, Splice These additional methods resembling Perl functions are available for operating on key-value pairs in the IxHash. The behavior is the same as the corresponding perl functions, except when a supplied hash key already exists in the hash. In that case, the existing value is updated but its order is not affected. To unconditionally alter the order of a supplied key-value pair, first "DELETE" the IxHash element. Keys Returns an array of IxHash element keys corresponding to the list of supplied indices. Returns an array of all the keys if called without arguments. Note the return value is mostly only useful when used in a list context (since perl will convert it to the number of elements in the array when used in a scalar context, and that may not be very useful). If a single argument is given, returns the single key corresponding to the index. This is usable in either scalar or list context. Values Returns an array of IxHash element values corresponding to the list of supplied indices. Returns an array of all the values if called without arguments. Note the return value is mostly only useful when used in a list context (since perl will convert it to the number of elements in the array when used in a scalar context, and that may not be very useful). If a single argument is given, returns the single value corresponding to the index. This is usable in either scalar or list context. Indices Returns an array of indices corresponding to the supplied list of keys. Note the return value is mostly only useful when used in a list context (since perl will convert it to the number of elements in the array when used in a scalar context, and that may not be very useful). If a single argument is given, returns the single index corresponding to the key. This is usable in either scalar or list context. Delete Removes elements with the supplied keys from the IxHash. Replace Substitutes the IxHash element at the specified index with the supplied value-key pair. If a key is not supplied, simply substitutes the value at index with the supplied value. If an element with the supplied key already exists, it will be removed from the IxHash first. Reorder This method can be used to manipulate the internal order of the IxHash elements by supplying a list of keys in the desired order. Note however, that any IxHash elements whose keys are not in the list will be removed from the IxHash. Length Returns the number of IxHash elements. SortByKey Reorders the IxHash elements by textual comparison of the keys. SortByValue Reorders the IxHash elements by textual comparison of the values. EXAMPLE
use Tie::IxHash; # simple interface $t = tie(%myhash, Tie::IxHash, 'a' => 1, 'b' => 2); %myhash = (first => 1, second => 2, third => 3); $myhash{fourth} = 4; @keys = keys %myhash; @values = values %myhash; print("y") if exists $myhash{third}; # OO interface $t = Tie::IxHash->new(first => 1, second => 2, third => 3); $t->Push(fourth => 4); # same as $myhash{'fourth'} = 4; ($k, $v) = $t->Pop; # $k is 'fourth', $v is 4 $t->Unshift(neg => -1, zeroth => 0); ($k, $v) = $t->Shift; # $k is 'neg', $v is -1 @oneandtwo = $t->Splice(1, 2, foo => 100, bar => 101); @keys = $t->Keys; @values = $t->Values; @indices = $t->Indices('foo', 'zeroth'); @itemkeys = $t->Keys(@indices); @itemvals = $t->Values(@indices); $t->Replace(2, 0.3, 'other'); $t->Delete('second', 'zeroth'); $len = $t->Length; # number of key-value pairs $t->Reorder(reverse @keys); $t->SortByKey; $t->SortByValue; BUGS
You cannot specify a negative length to "Splice". Negative indexes are OK, though. Indexing always begins at 0 (despite the current $[ setting) for all the functions. TODO
Addition of elements with keys that already exist to the end of the IxHash must be controlled by a switch. Provide "TIEARRAY" interface when it stabilizes in Perl. Rewrite using XSUBs for efficiency. AUTHOR
Gurusamy Sarathy gsar@umich.edu Copyright (c) 1995 Gurusamy Sarathy. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. VERSION
Version 1.22 27 February 2010 SEE ALSO
perl(1) perl v5.12.1 2010-02-27 Tie::IxHash(3)
All times are GMT -4. The time now is 07:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy