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
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)";
> > }
> >
>
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");
> }
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
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
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
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
# 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;
}
-
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
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:
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
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
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
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
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
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
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
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
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
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
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
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
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
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
--- 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
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
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
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
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
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
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
- 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
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
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
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
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..
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:
- 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
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
>
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 = $
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
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";
>$
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
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
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
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
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
"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!
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
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) {
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---
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
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
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
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
[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 = [
> -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
>
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
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=
> -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
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)'
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
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
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
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 = (
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
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
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
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
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
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
> @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}
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
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
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
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
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
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
> 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
> -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
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
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
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.
>
> [
[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
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
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
--- "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
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
--- 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,
- 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
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
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
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
--- 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
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.
--- 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
--- 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
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
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
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
601 - 700 of 700 matches
Mail list logo