Re: array numerical name...

2002-04-30 Thread Steven_Massey
Hi All - some interesting help - thanks drieux, chas, tim - all good pointers to resolve. I still cannot get the array naming to print - let me simplify $h=0; $TRY$h=3; print "$TRY$h"; does not work - I have tried ${TRY\$h} also any ideas ??? what am I missing ?? Thanks [EMA

Re: array numerical name...

2002-04-29 Thread Chas Owens
On Tue, 2002-04-30 at 00:23, drieux wrote: > > On Monday, April 29, 2002, at 02:42 , Chas Owens wrote: > [..] > > > > EVAL METHOD > > #!/usr/bin/perl -w > > use strict; > > > > my @fred = "one,two,three,four"; > > > > for my $a (0..3) { > > eval "my \@array$a=split(/,/, \@fred)"; > > } > > >

Re: array numerical name...

2002-04-29 Thread drieux
On Monday, April 29, 2002, at 02:42 , Chas Owens wrote: [..] > > EVAL METHOD > #!/usr/bin/perl -w > use strict; > > my @fred = "one,two,three,four"; > > for my $a (0..3) { > eval "my \@array$a=split(/,/, \@fred)"; > } > > for my $b (0..3) { > eval qq(print \@array$a[\$b], "\\n"); > }

Re: array numerical name...

2002-04-29 Thread Chas Owens
On Mon, 2002-04-29 at 17:19, [EMAIL PROTECTED] wrote: > Hi all - should be simple - but I cannot figure it out > > basically i want to name an array with a subscript ie world0[0] and world1[0] the >0/1 being a variable, i have tried to > produce a simple example > > For any help - thank

Re: array numerical name...

2002-04-29 Thread drieux
On Monday, April 29, 2002, at 02:19 , [EMAIL PROTECTED] wrote: > Hi all - should be simple - but I cannot figure it out > > basically i want to name an array with a subscript ie world0[0] and > world1[0] the 0/1 being a variable, i have tried to > produce a simple example do I feel you

RE: array numerical name...

2002-04-29 Thread Timothy Johnson
I think you may be barking up a branch of the right tree... It looks like what you REALLY want is an array of arrays. Check out 'perldoc perllol' and/or look up perl array of arrays in your favorite search engine, and that should get you started. -Original Message- From: [EMAIL PROTECT

RE: Array of file paths.

2002-04-05 Thread Timothy Johnson
You mean like this? foreach $file(@files){ open(OUTFILE,">$file"); print OUTFILE $data; } -Original Message- From: Helen Dynah [mailto:[EMAIL PROTECTED]] Sent: Friday, April 05, 2002 12:32 PM To: [EMAIL PROTECTED] Subject: Array of file paths. Hi again, I have an array of

Re: Array of file paths.

2002-04-05 Thread Tanton Gibbs
# loop through the file list assigning each name to $filename foreach my $filename (@files) { # open the file named $filename for overwrite. open FILE, ">$filename" or die "Could not open $filename: $!\n"; # print data to the file print FILE "data"; # close the file close FILE; } -

RE: Array question

2002-04-01 Thread Allison Ogle
Thanks for your help. I finally got it to work. Allison -Original Message- From: drieux [mailto:[EMAIL PROTECTED]] Sent: Monday, April 01, 2002 3:44 PM To: [EMAIL PROTECTED] Subject: Re: Array question On Monday, April 1, 2002, at 11:11 , Aman Raheja wrote: > $array-prob.pl p1

Re: Array question

2002-04-01 Thread drieux
On Monday, April 1, 2002, at 11:11 , Aman Raheja wrote: > $array-prob.pl p1: I loved the $field{$_}++; p2: but since you have stashed it all in a Hash, why not unpack the hash with my @arr = keys(%field); the counter proposal - http:

Re: Array question

2002-04-01 Thread ERIC Lawson - x52010
Sorry, there were a couple typos in my earlier response: > %count = (); > foreach $element (@array1) { $count{$element}++ } I should've included the semicolon at the end of the second line. > Your array of unique names is now available from the keys of %count; > the number of occurences of each

Re: Array question

2002-04-01 Thread Aman Raheja
Here's my solution. There will be shorter ways. I am new to perl, so this is how did it. At the prompt do $array-prob.pl #!/usr/bin/perl #File name : array-prob.pl my @arr; while(<>) { chomp($_); $field{$_}++; print "$_ $field{$_}\n"; my $set = 0; my $r

Re: Array question

2002-04-01 Thread ERIC Lawson - x52010
On Mon, 1 Apr 2002, Allison Ogle wrote: > I don't know how long the list is and eventually in the list some of > the names will repeat. I want to put these names in an array but I > don't want to repeat any names in the array and I want to keep a count > of how many times the name appears in the

RE: Array question

2002-04-01 Thread Timothy Johnson
You could always put them into a hash and then put them into an array later. foreach(@names){ $hash{$_} = 1; } my @array = keys %hash; -Original Message- From: Allison Ogle [mailto:[EMAIL PROTECTED]] Sent: Monday, April 01, 2002 8:08 AM To: a a Subject: Array question Hi, I have

Re: Array question

2002-04-01 Thread Glenn Meyer
Allison, Check out pages 133 - 135 in Learning Perl (3rd Edition) - the section "AutoIncrement and Autodecrement" section _ particularly the top of page 135 has an example for just this very question! I just read that last week so it popped right up in my mind. If you don't have the book, h

Re: Array question...

2002-03-28 Thread Chas Owens
On Thu, 2002-03-28 at 08:54, Michael D. Risser wrote: > OK here's the problem: > > I have an array that may or may not have been assigned to, if it has been > assigned to I need to do one thing, otherwise I need to do something else. > > I've tried many variations, but I'm having trouble determ

Re: Array question...

2002-03-28 Thread Michael D. Risser
On Thursday 28 March 2002 08:54 am, you wrote: > OK here's the problem: > > I have an array that may or may not have been assigned to, if it has been > assigned to I need to do one thing, otherwise I need to do something else. > > I've tried many variations, but I'm having trouble determining if i

RE: Array question...

2002-03-28 Thread John Edwards
try if (defined @array) { # do something } else { # It's not been created, do something else } HTH John -Original Message- From: Michael D. Risser [mailto:[EMAIL PROTECTED]] Sent: 28 March 2002 13:55 To: [EMAIL PROTECTED] Subject: Array question... OK here's the problem: I

Re: Array question

2002-02-13 Thread Kevin Butters
You and Mike showed me my error. I placed a 1 in the length field. It was inserting the element member I wanted but also removing one. Thanks, K --- "Brett W. McCoy" <[EMAIL PROTECTED]> wrote: > On Tue, 12 Feb 2002, Michael Fowler wrote: > > > Consider: > > > > @week = qw(Monday Wednesday Fr

Re: array question and ODBC note

2002-02-13 Thread Michael Fowler
On Wed, Feb 13, 2002 at 01:14:50PM -0800, John wrote: > Recently someone pointed out that it's better to use: > > while( defined( my $line = )) > > than > > while( my $line = ) In more recent versions of Perl (5.00503 and above) there is no need to wrap a defined around this specific loopin

Re: array references

2002-02-13 Thread Andrea Holstein
In article <[EMAIL PROTECTED]> wrote "Jon Serra" <[EMAIL PROTECTED]>: > Greetings, > > I have an array, each element will contain a reference to another array. How > can I dynamically generate each of those references such that each reference is >unique. I am > trying to create dynamic

Re: array references

2002-02-13 Thread Johnathan Kupferer
Jon Serra wrote: >Greetings, > >I have an array, each element will contain a reference to another array. How >can I dynamically generate each of those references such that each reference is >unique. I am trying to create dynamic 2d arrays. TIA JON > # # The key is understanding 'my' an

RE: array question

2002-02-13 Thread Brett W. McCoy
On Tue, 12 Feb 2002, Pankaj Warade wrote: > This is work > > my @array = ( 1, 2, 3, 4 ); > > print $#array; ---> size of array. No, $#array is the index of the last element of the array. To get the size of an array, just put the array into a scalar context: my $size = @array; print scalar(@ar

Re: array question

2002-02-13 Thread Briac Pilpré
On Wed, 13 Feb 2002 at 02:29 GMT, Pankaj Warade wrote: > This is work > > my @array = ( 1, 2, 3, 4 ); > > print $#array; ---> size of array. Actually, $#array holds the indices of the last element, not the size of the array. @array in scalar context returns the number of elements in the arra

RE: array question

2002-02-13 Thread Jonathan E. Paton
--- Pankaj Warade <[EMAIL PROTECTED]> wrote: > my @array = ( 1, 2, 3, 4 ); > > print $#array; ---> size of array. No, that is wrong. $#array gives the index of the last element, which is one less than the number of elements. Use this instead: print scalar @array; Jonathan Paton

RE: array question

2002-02-13 Thread Pankaj Warade
This is work my @array = ( 1, 2, 3, 4 ); print $#array; ---> size of array. p -Original Message- From: Chris Zampese [mailto:[EMAIL PROTECTED]] Sent: Sunday, February 10, 2002 5:19 AM To: [EMAIL PROTECTED] Subject: array question Hi all, Just wondering if someone could direct me i

Re: Array question

2002-02-12 Thread Brett W. McCoy
On Tue, 12 Feb 2002, Michael Fowler wrote: > Consider: > > @week = qw(Monday Wednesday Friday); > print "@week\n"; > > splice(@week, 1, 0, "Tuesday"); > print "@week\n"; > > splice(@week, 3, 0, "Thursday"); > print "@week\n"; Duh, didn't even consider using a 0 offset in

Re: Array question

2002-02-12 Thread Brett W. McCoy
On Tue, 12 Feb 2002, Kevin Butters wrote: > I have an array that I want to insert elements into. I > want to insert elements at specific points in the > array. > > Example: > > use strict: > > @week = ("Monday", "Wednesday", "Friday"); > > I want to expand the array to include Tuesday after > el

Re: Array question

2002-02-12 Thread Michael Fowler
On Tue, Feb 12, 2002 at 05:07:45PM -0800, Kevin Butters wrote: [snip] > @week = ("Monday", "Wednesday", "Friday"); > > I want to expand the array to include Tuesday after > element 0 and Thursday after element 1 > > I thought that splice was the correct way but > apparently not. It is, what mak

Re: Array question

2002-02-12 Thread Christopher Solomon
On Tue, 12 Feb 2002, Kevin Butters wrote: > Beginner question: > > .. > > > I have an array that I want to insert elements into. I > want to insert elements at specific points in the > array. > > Example: > > use strict: > > @week = ("Monday", "Wednesday", "Friday"); > > I want to expand the ar

Re: array question

2002-02-10 Thread Zhe Hong
The length (number of elements) of an array is returned when an array is called under a scalar context. @array = (1,2,3); $size = @array; # $size gets 3, number of elements in array print scalar @array; # prints the number 3 Hope this helps! Zhe - Original Message - From: "Chris Zampes

Re: Array Problem

2002-01-21 Thread Leon
- Original Message - From: "maureen" <[EMAIL PROTECTED]> To: "Leon" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Monday, January 21, 2002 8:39 AM Subject: Re: Array Problem > if ($username ne /$in{username}/) > { Anything in between the

Re: Array Problem

2002-01-21 Thread maureen
Thanks so much for your help on this. I tried this suggestion, but unfortunately, the array @indata does not seem to contain the usernames from the file pwdata.txt. I've been looking at this for hours. I hope someone can help me figure out what I am missing here. The objectives for this code and

RE: array and hash assignment

2002-01-18 Thread Christopher Solomon
On Fri, 18 Jan 2002, [iso-8859-1] amrit kumar wrote: > hi, > > what i want to proove is...supposer that i assign an > array @a = (1,2); and then i define another array @b > which is equal to @a.I have to proove that this is > done by assigning a copy of array @a to @b rather than > by refere

RE: array and hash assignment

2002-01-18 Thread Jeff 'japhy' Pinyan
On Jan 18, amrit kumar said: >what i want to proove is...supposer that i assign an >array @a = (1,2); and then i define another array @b >which is equal to @a.I have to proove that this is >done by assigning a copy of array @a to @b rather than >by reference. To determine if two variables point

RE: array and hash assignment

2002-01-18 Thread amrit kumar
hi, what i want to proove is...supposer that i assign an array @a = (1,2); and then i define another array @b which is equal to @a.I have to proove that this is done by assigning a copy of array @a to @b rather than by reference. Can you help me do that...i am bit confused .. thanks a lot..

RE: array and hash assignment

2002-01-18 Thread Hanson, Robert
You want to see if a scalar is actually a scalar or a ref? Try this... if ( ref $var ) { # It's a reference! } else { # It's not a reference } Rob -Original Message- From: amrit kumar [mailto:[EMAIL PROTECTED]] Sent: Friday, January 18, 2002 6:14 PM To: [EMAIL PROTECTED] Subject:

Re: Array Problem

2002-01-16 Thread Leon
- Original Message - From: "maureen" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> > Currently, the array seems to only be picking up the last name listed in > the text file. > @indata = ; > close(FILE); > foreach $i (@indata) > { > #remove hard return character from each record > chomp($i

RE: array of filenames to open

2002-01-09 Thread Yacketta, Ronald
would this be correct? I have a feeling no.. $_ = "$db_name\n" if ($. == 1 && $_ !~ /$db_name/); > -Original Message- > From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, January 09, 2002 12:21 > To: Yacketta, Ronald >

RE: array of filenames to open

2002-01-09 Thread Jeff 'japhy' Pinyan
On Jan 9, Yacketta, Ronald said: >I see that :) but not sure how to pull just the first line from the file >WITHOUT closing it and skipping to the next... Oh. Well, what are you trying to do? Change the first line of a set of files? >local @ARGV = @sleepystart; >while (<>) { > $line = $

RE: array of filenames to open

2002-01-09 Thread Yacketta, Ronald
Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, January 09, 2002 12:07 > To: Yacketta, Ronald > Cc: Beginners (E-mail) > Subject: RE: array of filenames to open > > > On Jan 9, Yacketta, Ronald said: > > >is their another trick to forgo the

RE: array of filenames to open

2002-01-09 Thread Jeff 'japhy' Pinyan
On Jan 9, Yacketta, Ronald said: >is their another trick to forgo the 4 lines above the "local @ARGV" ?? The ARGV trick is meant to AVOID the for loop. >foreach $file (@sleepystart) { >open FILE, "$file"; >$

RE: array of filenames to open

2002-01-09 Thread Yacketta, Ronald
print; } } Regards, Ron > -Original Message- > From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, January 09, 2002 11:50 > To: Yacketta, Ronald > Cc: Beginners (E-mail) > Su

Re: array of filenames to open

2002-01-09 Thread Jeff 'japhy' Pinyan
On Jan 9, Yacketta, Ronald said: >looking for a simple example of putting a set of filenames into an array >and then opening each of them for parsing. > >@files = ( "file1", "file2", "file3" ); > >foreach $file (@files) { > open FN, "< $file"; > do something here > close >} Thi

RE: array of filenames to open

2002-01-09 Thread Yacketta, Ronald
actualy it should be an array of variables that contain filenames @files = ( \$file1, \$file2, $file3 ); is that correct? > -Original Message- > From: Yacketta, Ronald [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, January 09, 2002 11:44 > To: Beginners (E-mail) > Subject: array of filen

Re: Array Length.

2001-12-18 Thread Michael Fowler
On Mon, Dec 17, 2001 at 11:04:10PM -0500, Michael R. Wolf wrote: > $length = @thearray > > The assignment operator supplies the scalar context. No, it's not the assignment operator that provides the scalar context, it's the assignment to a scalar. Consider: @anotherarray = @array; or

Re: Array Length.

2001-12-17 Thread Michael R. Wolf
Chris Spurgeon <[EMAIL PROTECTED]> writes: > A zillion ways. One is > > $length = scalar(@thearray); Which reduces to: $length = @thearray The assignment operator supplies the scalar context. The scalar pseudo-function is therefore not needed. OTOH print scalar @thearray; The scalar *is

Re: Array Length.

2001-12-17 Thread Michael R. Wolf
"Agustin Rivera" <[EMAIL PROTECTED]> writes: > print $#array; Off by one. That prints the last index, not the number of elements. print scalar @array If print isn't your use, try: $length = @array; $last_index = $#array; -- Michael R. Wolf All mammals learn by playing!

Re: Array Length.

2001-12-17 Thread Jenda Krynicky
From: "Agustin Rivera" <[EMAIL PROTECTED]> > print $#array; > > Agustin Rivera This has been discussed on this list lately I believe. This prints the max index of that array, not the array size. Since normaly you index arrays in Perl from 0 the $#array is the length-1, but it doesn't have to

Re: Array Length.

2001-12-17 Thread Etienne Marcotte
just a note to add to this method $#array gives the highest index, so the number of elements would be $#array+1 Also, $#array is useful when doing for to go thru to complete array since the first index is 0 and the last is nb of elements - 1 for(0..$#array) {#code here } # or foreach(@array) {

RE: Array Length.

2001-12-17 Thread Chris Spurgeon
A zillion ways. One is $length = scalar(@thearray); Chris Spurgeon Senior Design Technologist [EMAIL PROTECTED] ELECTRONIC INK One South Broad Street 19th Floor Philadelphia, PA 19107 www.electronicink.com t 215.922.3800 x(233) f 215.922.3880 -Original Message---

Re: Array Length.

2001-12-17 Thread Jenda Krynicky
From: Ryan Guy <[EMAIL PROTECTED]> > I need to know the fastest way to determine a length of an array. I > know there is a built in kind of thing somewhere. I just cant > remember it. Thanks $length = scalar( @array ); Jenda === [EMAIL PROTECTED] == http://Jenda.Kry

RE: Array Length.

2001-12-17 Thread Stout, Joel R
Assigning the array to a scalar will give you a count: push ( @initial_array, qw( apple orange bananna )); $a = @initial_array; print $a; prints 3 -Original Message- From: Ryan Guy [mailto:[EMAIL PROTECTED]] Sent: Monday, December 17, 2001 12:24 PM To: '[EMAIL PROTECTED]' Subject: Array

Re: Array Length.

2001-12-17 Thread Agustin Rivera
print $#array; Agustin Rivera Webmaster, Pollstar.com http://www.pollstar.com - Original Message - From: "Ryan Guy" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, December 17, 2001 12:24 PM Subject: Array Length. > I need to know the fastest way to determine a length of a

Re: Array References - Concatenation

2001-11-15 Thread Andrea Holstein
Andrea Holstein wrote: > > TMTOWTDI: > > @joined_array = map { [ @$array1[$_], @$array2[$_] ] } (0..$#array1); > Please excuse my little bugs: I wrote a little script that helps to understand: Hallo! use strict; my $array1 = [ [11,12], [21,22

Re: Array References - Concatenation

2001-11-15 Thread Andrea Holstein
[EMAIL PROTECTED] wrote: > > Friends, > > I have two, two-dimensional array references, and I need to join the rows of > each array. > > $array1 = [ > [11,12], > [21,22], > [31,32] > ]; > and > $array2 = [

RE: Array References - Concatenation

2001-11-14 Thread Bob Showalter
> -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, November 14, 2001 2:21 PM > To: [EMAIL PROTECTED] > Subject: Array References - Concatenation > > > Friends, > > I have two, two-dimensional array references, and I need to > join the rows of >

RE: Array References - Concatenation

2001-11-14 Thread Gibbs Tanton - tgibbs
I guess you could do for (0..$#{ $array1 }) { push( @{ $array1->[$_] }, @{ $array2->[$_] } ); } I'm not sure if that is any clearer or not. -Original Message- From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: 11/14/2001 1:21 PM Subject: Array References - Concatenation Friends, I

Re: Array problems!

2001-11-13 Thread Greg Meckes
Maybe try: open(MYFILE, $match) || die "Can't open file: $!"; my @filelist = ; close(MYFILE); chomp @filelist; foreach (@filelist) { find \&wanted($_), "."; } sub wanted { my $File = shift; print "Match found at : $File::Find::name\n" if $File; } For the $b array just: while (defined($b=

RE: Array problems!

2001-11-13 Thread Bob Showalter
> -Original Message- > From: Ben Crane [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, November 13, 2001 10:30 AM > To: [EMAIL PROTECTED] > Subject: Array problems! > > > I create a dummy file with 4 filenames in it...I have > read these 4 names into @filelist...and when I pass > the array t

RE: Array with selected records.

2001-11-03 Thread Wagner-David
In your test you are using numeric == vs eq string comparsion for one thing. Also switch the print to: print OUTFILE1 $rec; Wags ;) -Original Message- From: Mark Weisman [mailto:[EMAIL PROTECTED]] Sent: Saturday, November 03, 2001 11:09 To: 'Beginners@Perl. Org (E-mail)'

Re: array slice syntax

2001-11-03 Thread Paul Johnson
On Sat, Nov 03, 2001 at 05:49:37PM +0100, Thomas Hofer wrote: > Hi! > > As a perl beginner, I have a silly question about > array-slices-syntax: > > That's clear: > > perl -e '@a=(a,b,c);print "@a[1..2]\n"' > ==> b c > > perl -e '@a=(a,b,c);print "$a[1]\n"' > ==> b > > But why does $array[ra

Re: array of hashes

2001-10-31 Thread Michael Fowler
On Wed, Oct 31, 2001 at 09:53:58AM -0800, Sofia wrote: [snip] > %systems = ( >sgi => ["sgi1", "sgi2"], >linux => ["linux1", "linux2"], >dec => ["dec1", "dec2"] > }; [snip] > %default = ( > sgi => ["sgi-help","/bin/csh","/home"], > linux => > ["someaddress-help","/bin/bas

Re: array of hashes

2001-10-31 Thread Jeff 'japhy' Pinyan
On Oct 31, Sofia said: >So in the example that Daniel shows, how would I get >(reference) the value for the shell path for the sgi >system? Using the data structure: >> %systems = ( >> sgi => { defaults => >> ["sgi-help","/bin/csh","/home"], >> machines => ["sgi1", "sgi2

Re: array of hashes

2001-10-31 Thread Sofia
So in the example that Daniel shows, how would I get (reference) the value for the shell path for the sgi system? --- Daniel Gardner <[EMAIL PROTECTED]> wrote: > S> I have a systems hash that contains the type of > system > S> as keys and the name of the machines as values: > > S> %systems = (

Re: array of hashes

2001-10-31 Thread Sofia
Daniel, I am recreating the systems password, group and shadow (when applicable) files. So if the script is run on an sgi system, for example, the files location is /etc. If it is run on a linux machine is /usr/local/system. If there are new users, create new directories for them: for sgis on

Re: array of hashes

2001-10-31 Thread Daniel Gardner
S> I have a systems hash that contains the type of system S> as keys and the name of the machines as values: S> %systems = ( S>sgi => ["sgi1", "sgi2"], S>linux => ["linux1", "linux2"], S>dec => ["dec1", "dec2"] S> }; S> Now, each type of system has default values like an S> email

Re: array of arrays

2001-10-18 Thread _brian_d_foy
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] (Michael Fowler) wrote: > $array[$i][$j][$k][$l][$m] eq $list[$l][$m] > However, this is the first time I've seen someone intentionally using such a > large-dimension array. What is this for? i've used many more dimensions than that ;) -- bri

Re: array of arrays

2001-10-18 Thread Michael Fowler
On Thu, Oct 18, 2001 at 02:28:41PM -0600, Tyler Cruickshank wrote: > $array[$i][$j][$k] = [ @list ]; where, @list is a 2-D array ie. $list[][]. > > How do I access the individual elements of the array @list once Ive put it > into the array @array? $array[$i][$j][$k][$l][$m] eq $list[$l][$m] H

Re: Array of Hashes?

2001-09-24 Thread Jeff 'japhy/Marillion' Pinyan
On Sep 24, Pete Sergeant said: >@hosts = sort { %{$a}->{'name'} <=> %{$b}->{'name'} } @hosts; That (%{$x}->{key}) works for an ugly reason. It's probably a bug. @hosts = sort { $a->{name} cmp $b->{name} } @hosts; -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~jap

Re: Array of Hashes?

2001-09-24 Thread Richard J. Barbalace
Jonathan Batchelor writes: > I have a data structure similar to the following: > > @hosts = ( list of hashes like below ... ); > %hosts = ( name => "hostname", >ipaddr => "www.xxx.yyy.zzz", >location => "location" > ); > > How can produce a sorted list of the ha

Re: Array of Hashes?

2001-09-24 Thread Pete Sergeant
> @hosts = ( list of hashes like below ... ); > %hosts = ( name => "hostname", > ipaddr => "www.xxx.yyy.zzz", > location => "location" >); > > How can produce a sorted list of the hashes based on the hostname and then > access each hash to print the details. > @hosts = sort { %{$a}

Re: Array of Hashes?

2001-09-24 Thread register
You can do a schwartzian transform @hosts = (blah..blah..blah); my @sorted = map { $_->[0] } sort { $a->[1] cmp $b->[1] } map { [$_,$_->{name} } @hosts; foreach my $h (@sorted) { foreac

Re: array as an class attribute

2001-09-08 Thread Brett W. McCoy
On Sat, 8 Sep 2001, Gustavo A. Baratto wrote: > Thanks for the help. I wasn't initializing the $self->{ARRAY} with []. > But later in the code I need to do something like this: > > @self->{ARRAY} = @another_array; # of course this is giving me an error. You still need an array reference: $self

Re: array as an class attribute

2001-09-08 Thread Gustavo A. Baratto
ohhh boy... It worked greatly. I have a lng way til I get all those tricks. Thank you very much. "Jeff 'Japhy/Marillion' Pinyan" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > On

Re: array as an class attribute

2001-09-08 Thread Jeff 'japhy/Marillion' Pinyan
On Sep 8, Gustavo A. Baratto said: >Thanks for the help. I wasn't initializing the $self->{ARRAY} with []. >But later in the code I need to do something like this: > >@self->{ARRAY} = @another_array; # of course this is giving me an error. @{ $self->{ARRAY } = @another_array; or $self->{A

Re: array as an class attribute

2001-09-08 Thread Gustavo A. Baratto
Thanks for the help. I wasn't initializing the $self->{ARRAY} with []. But later in the code I need to do something like this: @self->{ARRAY} = @another_array; # of course this is giving me an error. Do I have to do: for ($i=0;$i<$#another_array;$i++) { $self->{ARRAY}[$i] = $another_arra

Re: array as an class attribute

2001-09-08 Thread Brett W. McCoy
On Sat, 8 Sep 2001, Gustavo A. Baratto wrote: > How can I have an array in a class attribute? > > In my constuctor this is not working: (I need $self->{ARRAY} to be an array) > > > sub new > { > my $class = shift; > my $self = { }; > $self->{IFCONFIG} = "/etc/ifconfig.temp"; > $se

Re: Array::compare question

2001-07-29 Thread Rachel Coleman
> Does someone know if the array::compare module can handle array of > arrays? I haven't seen anyone answer this yet. Based on the documentation (http://theoryx5.uwinnipeg.ca/CPAN/data/Array-Compare/Compare.html), Array::Compare takes 2 arrays and tells you if they are the same, or different, w

RE: array contents to a file

2001-07-26 Thread Bob Showalter
> -Original Message- > From: John Edwards [mailto:[EMAIL PROTECTED]] > Sent: Thursday, July 26, 2001 4:43 AM > To: 'Ron Smith'; [EMAIL PROTECTED] > Subject: RE: array contents to a file > > ... > foreach $element(@array) { > print FILE

RE: array contents to a file

2001-07-26 Thread John Edwards
Like this?? @array = qw(one two three four); open FILE, ">c:\\out.txt" or die "Can't create c:\\out.txt: $!"; foreach $element(@array) { print FILE "$element\n"; } close FILE; -Original Message- From: Ron Smith [mailto:[EMAIL PROTECTED]] Sent: 26 July 2001 09:36 To: [EMAIL PROTE

Re: array slice question

2001-06-26 Thread Michael Fowler
On Tue, Jun 26, 2001 at 04:46:24PM -0400, Bradford Ritchie wrote: > ...but I really need to print everything after the 8th element. If the > ...array were named, I could do something like this: > > @arr = split(/:/); > print @arr[1,6,8..$#arr]); Your asked question was answered well by St

RE: array slice question

2001-06-26 Thread Peter Cornelius
I don't think so. I do (split)[-1] regularly and it works fine. If you left out the parens however it would think this was a pattern to match. I was told by someone on perlmonks that the failure of [3 .. -1] with split is something that should be fixed in subsequent versions of Perl. > > [

Re: array slice question

2001-06-26 Thread royce . wells
[1,6,8..-1] in this case "-" is seen as a metacharacter inside the character class and is not seen as -1 Hi, I have an unnamed array which I created from splitting up a colon separated string: $_ = "0th:1st:2nd:3rd:4th:5th:6th:7th:Some random text: might have :colons: or might n

Re: array slice question

2001-06-26 Thread dave hoover
Bradford wrote: > Hi, > > I have an unnamed array which I created from > splitting up a colon separated string: > > $_ = "0th:1st:2nd:3rd:4th:5th:6th:7th:Some > random text: might have :colons: or might not" > print ((split /:/)[1,6,8]); > > ...but I really need to print everythi

RE: array slice question

2001-06-26 Thread Stephen Nelson
Well, if you're OK with printing the colons in the last field, you could simply say: print ( ( split(/:/, $_, 9) )[1,6,8] ); Since that'll absorb all of the ending fields into the ninth (from zero, so index 8) field. That would be the correct thing to do if the colons in the ending field are not

RE: array of variables

2001-05-31 Thread Paul
--- "Hill, Ronald" <[EMAIL PROTECTED]> wrote: > try > use vars qw($sec $min $hour $mday $mon $year); This will satisfy strict, but in case anyone wonders, these are still globals. If you do this in the main body of your program, these are actually $main::sec, $main::min, ... $main::year. That

RE: array of variables

2001-05-31 Thread Hill, Ronald
so i've discovered the wonders of use strict; (it wasn't in my tutorial) and i'm trying to declare this array: my @timelog($sec,$min,$hour,$mday,$mon,$year) = localtime(time)[0,1,2,3,4,5]; and i get the error: Global symbol "$sec" requires explicit package name etc etc i tried putting 'my' be

Re: array of variables

2001-05-31 Thread Paul
--- Nichole Bialczyk <[EMAIL PROTECTED]> wrote: > so i've discovered the wonders of use strict; (it wasn't in my > tutorial) and i'm trying to declare this array: It'll cause a little headache now, and save you a LOT later. =o) -w and strict are your friends! lol! > my @timelog($sec,$min,$hour,

Re: array inside a hash

2001-05-31 Thread M.W. Koskamp
- Original Message - From: Gary Stainburn <[EMAIL PROTECTED]> To: Perl Beginners <[EMAIL PROTECTED]> Sent: Thursday, May 31, 2001 1:21 PM Subject: array inside a hash > Hi all, > > I'm writing a small script to collect info from various system commands > to produce a small meaningfull r

Re: array inside a hash

2001-05-31 Thread Ondrej Par
Hi, correct is: $pvolumes{$pv}->{volumes} ||= []; ## create empty array if it wasn't yet used push @{$pvolumes{$pv}->{volumes}}, "$lv:$lp:$pp:$dist"; On Thursday 31 May 2001 13:21, Gary Stainburn wrote: > Hi all, > > I'm writing a small script to collect info from various system commands > to p

Re: array location

2001-05-29 Thread Nichole Bialczyk
i feel really stupid now. i can't believe i actually did that. i guess learning perl is starting to frazzle my brain. it wasn't an array, but an actual IP address. since it was supposed to store blocked addresses, for some reason when i saw just one entry, i thought that it was something diffe

Re: array location

2001-05-29 Thread Brett W. McCoy
On Tue, 29 May 2001, Nichole Bialczyk wrote: > ok, so i'm trying to work my way through this script. there are blocked > addresses and they are stored in an array at something like > 'd-131-151-136-22...xxx'. Where do I find this location on the > unix account? I need to be able to add mo

Re: Array Question

2001-05-17 Thread Paul
--- jane doe <[EMAIL PROTECTED]> wrote: > How do I remove duplicate items from an array? I apologize for being > a "newbie". :) my @a = (1,2,2,3,4,4,5); my %h; @h{@a} = (); # hash keys are unique @a = sort keys %k; The line @h{@a} =(); is a bulk assignment of all elements of @a as keys in hash

Re: Array Question

2001-05-16 Thread Jeff Pinyan
On May 16, jane doe said: >How do I remove duplicate items from an array? I apologize for being a >"newbie". :) Please read 'perldoc -q duplicate' or 'perldoc -q unique'. You can see these answers in Perl FAQ #4, online at http://www.perldoc.org/, or on your computer via the 'perldoc' command.

RE: Array Size Question(s)

2001-05-14 Thread Paul
--- Peter Cornelius <[EMAIL PROTECTED]> wrote: > A cool control structure in perl is the for or foreac loop. With it > you don't need to know the size of the array you can just >for my $thing (@A) { > #do stuff with $thing >} This is very efficient; just keep in mind that $thing i

Re: Array Size Question(s)

2001-05-14 Thread Paul
--- Collin Rogowski <[EMAIL PROTECTED]> wrote: > You get the size of an array by using it in a scalar context. > $size = @a; This is entirely correct. But for those of you who prefer a more explicit syntax, you can put any expression into scalar context with the "scalar" keyword. For my own tast

RE: Array Size Question(s)

2001-05-14 Thread Peter Cornelius
A cool control structure in perl is the for or foreac loop. With it you don't need to know the size of the array you can just for my $thing (@A) { #do stuff with $thing } If you're familiar with shell syntax this is kinda like the 'for i in list' construct. Books - You might check

Re: Array Size Question(s)

2001-05-14 Thread Collin Rogowski
First part: You get the size of an array by using it in a scalar context. Sounds complicated? Scalar context means that the left side of an assignment is a scalar. So you just write: $size = @a; and you get the size of the array @a. Another method would be to get the index of the last element a

Re: Array Size Question(s)

2001-05-14 Thread Paul Cotter
while($ansNum < $numOfAns) where $ansNum starts at zero and is incremented until it is at $numOfAns(from the split line above, it's value should represent the number of elements in @A). This all works, but I would like to improve it and make it so that the user making the text file doesn't have t

<    2   3   4   5   6   7   8   >