On 20/11/2011 04:14, Chris Charley wrote:
Well, if Dr Ruud is right, and you shouldn't replace the undefs in the
original arrays, then the following program wouldn't be correct. It
changes the original array (data).
On 20/11/2011 00:23, Dr.Ruud wrote:
Unless you really want to change your
Unless you really want to change your data, use map().
Ruud didn't say that you shouldn't change the data, only that you should
use map unless that was what you wanted. Who knows what the OP wants.
Rob
Sorry for the delay.
What Shlomi Fish mentioned was I wanted. Thanks for all your
'
]
];
To print 'fred' , I can use like : print $ref_to_AoA-[0]-[0];
But What I want is, I want to replace all 'undef' to a string 'foo'. What
is the efficient way I will replace it (the array is larger then what I am
showing above). Any help and explanation will be appreciated.
If you want just to print
'
]
];
To print 'fred' , I can use like : print $ref_to_AoA-[0]-[0];
But What I want is, I want to replace all 'undef' to a string 'foo'. What
is the efficient way I will replace it (the array is larger then what I am
showing above). Any help and explanation will be appreciated.
Thanks Rg
Mohan L
I want is, I want to replace all 'undef' to a string 'foo'. What
is the efficient way I will replace it (the array is larger then what I am
showing above). Any help and explanation will be appreciated.
Thanks Rg
Mohan L
',
undef,
'judy'
]
];
To print 'fred' , I can use like : print $ref_to_AoA-[0]-[0];
But What I want is, I want to replace all 'undef' to a string 'foo'. What
is the efficient way I will replace it (the array is larger then what I am
showing above). Any help
On 2011-11-19 19:21, Mohan L wrote:
But What I want is, I want to replace all 'undef' to a string 'foo'.
Unless you really want to change your data, use map().
--
Ruud
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
}
32 elsif ($tab eq 3) {
33 $sub3[$h][$i] = $title;
34 $i++;
35 }
36 }
this strategy works for only if there are main and sub titles. it
doesn't work for 2. and 3. level sub titles, because of the change of 1.
level sub title array.
putting them into different files
is incomplete and I'm doing an array within an array
which is incorrect. Please help.
You are not using arrays you are using hashes.
Here's what I want to do; I have to flat files (pipe delimited,
export from a database) that I want to parse through and assign
variables for each column. Basically
Hey all,
I'm new with Perl and need help with this simple script. I'm still
playing around with the script below to get a feel for Perl. My script
below is incomplete and I'm doing an array within an array which is
incorrect. Please help.
Here's what I want to do; I have to flat files
On 29 Oct 2007 at 8:42, Mike Tran wrote:
Hey all,
I'm new with Perl and need help with this simple script. I'm still
playing around with the script below to get a feel for Perl. My script
below is incomplete and I'm doing an array within an array which is
incorrect. Please help
PROTECTED]
Sent: 29 October 2007 15:30
To: beginners @ perl. org
Subject: Re: array within array
On 29 Oct 2007 at 8:42, Mike Tran wrote:
Hey all,
I'm new with Perl and need help with this simple script. I'm still
playing around with the script below to get a feel for Perl. My script
On Monday 29 October 2007 07:29, Beginner wrote:
while (EXCLUDE) {
chomp;
my @fields = split(/|/,$_);
^^^
$exclude_bases{$F[0]} = 0; # $f[0] contains base_no
}
close(EXCLUDE);
open(BASE,base.txt)|| die(Could not open file!);
while (BASE) {
Andrew Curry schreef:
be very careful with exists, it auto creates the structure
use Data::Dumper;
my %hash;
if (exists $hash{a}{b}) {}
print Dumper(\%hash)
then the next time you use exists it is there.
defined is much safer as it doesnt do this.
No, the difference here
On Monday 29 October 2007 06:42, Mike Tran wrote:
Hey all,
Hello,
I'm new with Perl and need help with this simple script. I'm still
playing around with the script below to get a feel for Perl. My
script below is incomplete and I'm doing an array within an array
which is incorrect. Please
On Oct 29, 6:42 am, [EMAIL PROTECTED] (Mike Tran) wrote:
Hey all,
I'm new with Perl and need help with this simple script. I'm still
playing around with the script below to get a feel for Perl. My script
below is incomplete and I'm doing an array within an array which is
incorrect. Please
beginners
Subject: Re: array within array
On Monday 29 October 2007 06:42, Mike Tran wrote:
Hey all,
Hello,
I'm new with Perl and need help with this simple script. I'm still
playing around with the script below to get a feel for Perl. My
script below is incomplete and I'm doing an array within
Matthew Whipple schreef:
If you're looking for the last element then you could
use $files[$#files]
Or $files[-1].
--
Affijn, Ruud
Gewoon is een tijger.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/
I use the scalar keyword on occasion:
#!/usr/bin/perl
my @arr = qw/adfs adsf 4fd feqw3 f432d/;
print The size of the array is . scalar (@arr) . \n;
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/
line, it initializes the files array and I can't use it
after? Why is that?
I actually guessed the code to be trying to go one way but am now
changing my guess. Don't say initialize when you don't mean it, that
implies that the variable previously contained no value.
I now
Joseph L. Casale wrote:
Sorry, it is an array I used above this block of code.
jlc
That could have easily been guessed (that's one of the few options).
The question is what's in it and what are you trying to do with it.
-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL
[EMAIL PROTECTED] wrote:
I had the following code:
open (FILEOUT, $OutDir/info) or die $!;
print FILEOUT text = abc\n;
my $Tmp = ++$#files;
print FILEOUT moretext = $Tmp\n;
When I add the 3rd line, it initializes the files array and I can't
On 10/19/07, Joseph L. Casale [EMAIL PROTECTED] wrote:
open (FILEOUT, $OutDir/info) or die $!;
print FILEOUT text = abc\n;
my $Tmp = ++$#files;
Huh?
print FILEOUT moretext = $Tmp\n;
When I add the 3rd line, it initializes the files array
Sorry, it is an array I used above this block of code.
jlc
-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of yitzle
Sent: October-19-07 11:16 AM
To: Joseph L. Casale
Cc: beginners@perl.org
Subject: Re: Printing size of array unitializes array?
What are you
;
my $Tmp = ++$#files;
print FILEOUT moretext = $Tmp\n;
When I add the 3rd line, it initializes the files array and I can't use it
after? Why is that?
I now have:
open (FILEOUT, $OutDir/info) or die $!;
print FILEOUT text = abc\n;
print
I had the following code:
open (FILEOUT, $OutDir/info) or die $!;
print FILEOUT text = abc\n;
my $Tmp = ++$#files;
print FILEOUT moretext = $Tmp\n;
When I add the 3rd line, it initializes the files array and I can't use it
after? Why is that?
I
: Array of Array refs
On May 29, 6:06 am, [EMAIL PROTECTED] (Paul Lalli) wrote:
On May 29, 4:58 am, [EMAIL PROTECTED] (Brian) wrote:
On May 28, 6:14 pm, [EMAIL PROTECTED] (Paul Lalli) wrote:
oh yes, more important than all that minutiae... the push did
not work for me in the working code
step
toward becoming a better programmer.
hmmm, misunderstanding there. The push worked fine in the sample I
posted, but not in the more complex working program I had simplified
as an example.
The array was being rewritten.
Then you didn't delcare your variables in the correct scope
On May 28, 6:04 pm, [EMAIL PROTECTED] (Paul Lalli) wrote:
On May 28, 3:22 pm, [EMAIL PROTECTED] (Brian) wrote:
my variable names end with A for array and H for hash,
Pointless. Variable names in Perl identify what kind of variable they
are. @ for arrays, % for hashes. [ ] for accessing
On May 29, 5:30 am, [EMAIL PROTECTED] (Brian) wrote:
On May 28, 6:04 pm, [EMAIL PROTECTED] (Paul Lalli) wrote:
On May 28, 3:22 pm, [EMAIL PROTECTED] (Brian) wrote:
my variable names end with A for array and H for hash,
Pointless. Variable names in Perl identify what kind of variable
() works perfectly well. It adds
elements to an array. If your program produced incorrect results, it
is because you did something wrong, not because push didn't work. Of
course, as you haven't shown any code that produces these undesired
results, we can only guess as to what your actual problem
Brian wrote:
Paul Lalli wrote:
Brian wrote:
my variable names end with A for array and H for hash,
Pointless. Variable names in Perl identify what kind of variable they
are. @ for arrays, % for hashes. [ ] for accessing an element of a
hash, { } for accessing element of a hash.
no, I
On May 29, 10:16 am, [EMAIL PROTECTED] (Rob Dixon) wrote:
Brian wrote:
I agree with you Brian. I have been posting on this list for around four
years, and rarely have I seen 'help' that is expressed with such vitriol
as Paul's has been.
I'm truly sorry you feel that way, Brian. My responses
On May 29, 11:10 am, [EMAIL PROTECTED] (Paul Lalli) wrote:
On May 29, 10:16 am, [EMAIL PROTECTED] (Rob Dixon) wrote:
Brian wrote:
I agree with you Brian. I have been posting on this list for around four
years, and rarely have I seen 'help' that is expressed with such vitriol
as Paul's
Brian schreef:
Changing @ to $ is confusing...
Huh? @ means array, $ means scalar; there is nothing to change.
--
Affijn, Ruud
Gewoon is een tijger.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/
On May 29, 3:21 pm, [EMAIL PROTECTED] (Dr.Ruud) wrote:
Brian schreef:
Changing @ to $ is confusing...
Huh? @ means array, $ means scalar; there is nothing to change.
Presumably, he meant that
@array
identifies the entire array, while
$array[0]
identifies the first element of the array, thus
Intrah onat Diria ..
, ** wrote Revera y:
Changing @ to $ is confusing...
this is different in perl6
, http://dev.perl.org/perl6/doc/design/syn/S09.html
the following could be unreadable @ 1180470350 :::
hbeingspiel
, 0::-
, 1::',|
, 0::|
, 1::vert{
,
On 29 May 2007 13:04:42 -0700, Paul Lalli [EMAIL PROTECTED] wrote:
On May 29, 3:21 pm, [EMAIL PROTECTED] (Dr.Ruud) wrote:
Brian schreef:
Changing @ to $ is confusing...
Huh? @ means array, $ means scalar; there is nothing to change.
Presumably, he meant that
@array
identifies the entire
simplified
as an example.
nope, sorry, you're wrong. push() works perfectly well. It adds
elements to an array. If your program produced incorrect results, it
is because you did something wrong, not because push didn't work.
ugh. pedantic semantics...
Of
course, as you haven't shown any
Hi All-
I am trudging through some DBI, XML, etc.. I had a problem and was
baffled by how to get at array elements out of a series of pushed
array refs. But, by simplifying the problem, I found that the syntax I
used was in error. here is the small sample, already debugged. Hope
this helps
Brian wrote:
Hi All-
I am trudging through some DBI, XML, etc.. I had a problem and was
baffled by how to get at array elements out of a series of pushed
array refs. But, by simplifying the problem, I found that the syntax I
used was in error. here is the small sample, already debugged. Hope
On May 28, 12:00 am, [EMAIL PROTECTED] (Brian) wrote:
I am trudging through some DBI, XML, etc.. I had a problem and was
baffled by how to get at array elements out of a series of pushed
array refs.
What's to be baffled by? Have you read:
perldoc perlreftut
perldoc perllol
perldoc perldsc
On May 27, 9:00 pm, [EMAIL PROTECTED] (Brian) wrote:
Hi All-
I am trudging through some DBI, XML, etc.. I had a problem and was
baffled by how to get at array elements out of a series of pushed
array refs. But, by simplifying the problem, I found that the syntax I
used was in error. here
On May 27, 9:00 pm, [EMAIL PROTECTED] (Brian) wrote:
Hi All-
I am trudging through some DBI, XML, etc.. I had a problem and was
baffled by how to get at array elements out of a series of pushed
array refs. But, by simplifying the problem, I found that the syntax I
used was in error. here
On May 28, 3:22 pm, [EMAIL PROTECTED] (Brian) wrote:
my variable names end with A for array and H for hash,
Pointless. Variable names in Perl identify what kind of variable they
are. @ for arrays, % for hashes. [ ] for accessing an element of a
hash, { } for accessing element of a hash.
yes
On May 28, 3:26 pm, [EMAIL PROTECTED] (Brian) wrote:
On May 27, 9:00 pm, [EMAIL PROTECTED] (Brian) wrote:
Hi All-
I am trudging through some DBI, XML, etc.. I had a problem and was
baffled by how to get at array elements out of a series of pushed
array refs. But, by simplifying
--- John W. Krahn [EMAIL PROTECTED] wrote:
I have an array of array look like this:
@array_of_array=(
[1,2,3,4,5],
[1,2,3,4,5],
[1,2,3,4,5],
[1,2,3,4,5]
)
How do I get the total values for each colume
chen li wrote:
: $total[ $column ] += $row-[ $column ];
:
: Can you or anyone else explain it a bit more?
It is short for this.
$total[ $column ] = $total[ $column ] + $row-[ $column ];
HTH,
Charles K. Clarkson
--
Mobile Homes Specialist
Free Market Advocate
Web Programmer
254
Dear all,
I have an array of array look like this:
@array_of_array=(
[1,2,3,4,5],
[1,2,3,4,5],
[1,2,3,4,5],
[1,2,3,4,5]
)
How do I get the total values for each colume, such as
$column1=1+1+1+1;
$column2=2+2+2+2;
$column3=3+3+3+3;
...
Thanks
-Original Message-
From: chen li [mailto:[EMAIL PROTECTED]
Sent: Friday, August 18, 2006 7:00 PM
To: beginners@perl.org
Subject: calculate the value in an array of array
Dear all,
I have an array of array look like this:
@array_of_array=(
[1,2,3,4,5
chen li schreef:
I have an array of array look like this:
@array_of_array=(
[1,2,3,4,5],
[1,2,3,4,5],
[1,2,3,4,5],
[1,2,3,4,5]
)
How do I get the total values for each colume
#!/usr/bin/perl
use warnings ;
use strict ;
my @AoA
chen li wrote:
Dear all,
Hello,
I have an array of array look like this:
@array_of_array=(
[1,2,3,4,5],
[1,2,3,4,5],
[1,2,3,4,5],
[1,2,3,4,5]
)
How do I get the total values for each colume, such as
$column1=1+1+1+1;
$column2=2+2
chen li wrote:
I have an array of array look like this:
@array_of_array=(
[1,2,3,4,5],
[1,2,3,4,5],
[1,2,3,4,5],
[1,2,3,4,5]
)
How do I get the total values for each colume, such as
$column1=1+1+1+1;
$column2=2+2+2+2;
$column3=3+3+3
On Fri, Aug 18, 2006 at 06:29:36AM -0700, chen li wrote:
Dear all,
I have an array of array look like this:
@array_of_array=(
[1,2,3,4,5],
[1,2,3,4,5],
[1,2,3,4,5],
[1,2,3,4,5]
)
How do I get the total values for each colume
row. Like an old turbo pascal implementation of
strings did ;-)
That's twisted. g
(The array isn't guaranteed to be square either.)
--
Affijn, Ruud
Gewoon is een tijger.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org
my $localtime;
@$localtime{qw / second minute hour mday month year weekday yearday isdst /} =
localtime(time);
[1] A style nit:
Speaking of nitpicks:
my %localtime;
If you DO need to iterate across all the indices for an array ( rarely
necessary if you have designed your data correctly
my $localtime;
@$localtime{qw / second minute hour mday month year weekday yearday isdst /
} =
localtime(time);
[1] A style nit:
Speaking of nitpicks:
my %localtime;
Assuming you are suggesting making that change, I'd reccomend against
it, unless you wish to elicit the following
On 6/10/05, Lawrence Statton [EMAIL PROTECTED] wrote:
my $localtime;
@$localtime{qw / second minute hour mday month year weekday yearday isdst
/
} =
localtime(time);
[1] A style nit:
Speaking of nitpicks:
my %localtime;
Assuming you are suggesting making that change,
Huh. So it does... that doesn't look like it's making a reference,
though. I think I would write that as @{$localtime}{ ... } for
clarity.
I only got out my snippy voice because it will be a snowy day here
when I post example code to the list that hasn't actually been tested.
It does not
On 6/10/05, Lawrence Statton [EMAIL PROTECTED] wrote:
Huh. So it does... that doesn't look like it's making a reference,
though. I think I would write that as @{$localtime}{ ... } for
clarity.
As to the clarity question. To my eyes, I find spurious {} tend to
diminish rather than
Hi All
Prob: I want to convert all the elememts of an array to ascalor variable that I
can use latter on in my code
e.g.
my @array=qw/balli johney bobby/;
now here i need 3 different variable with the above values i.e.
my $name1=balli ;
my $name2=johney ;
my $name3=bobby ;
Soln so far
[EMAIL PROTECTED] wrote:
Hi All
Hello,
Prob: I want to convert all the elememts of an array to ascalor variable that I can use latter on in my code
Each element of an array *is* a scalar so why do you think you need to do this?
e.g.
my @array=qw/balli johney bobby/;
now here i need 3
Hi All
Prob: I want to convert all the elememts of an array to ascalor variable that
I can use latter on in my code
e.g.
my @array=qw/balli johney bobby/;
now here i need 3 different variable with the above values i.e.
my $name1=balli ;
my $name2=johney ;
my $name3=bobby
[EMAIL PROTECTED] wrote:
Each element of an array *is* a scalar so why do you think you need to do this?
my ( $name1, $name2, $name3 ) = @array;
True,
But how would I know how many ($name) to use in the line above In my case
for a perticular user I have some bad volumes which
[EMAIL PROTECTED] wrote:
Hi All
Prob: I want to convert all the elememts of an array to ascalor variable that
I can use latter on in my code
e.g.
my @array=qw/balli johney bobby/;
now here i need 3 different variable with the above values i.e.
my $name1=balli ;
my $name2=johney ;
my $name3
[EMAIL PROTECTED] wrote:
Hi All
Prob: I want to convert all the elememts of an array to ascalor variable tha
t I can use latter on in my code
e.g.
my @array=qw/balli johney bobby/;
now here i need 3 different variable with the above values i.e.
my $name1=balli ;
my $name2=johney
Randal L. Schwartz [RLS], on , , 2005 at 05:47 (-0700) wrote about:
RLS $wanted ||= $input =~ /$_/ for @filter;
RLS $wanted;
RLS } @input;
RLS Note the use of ||= for short-circuiting the tests once a good filter
RLS is found. You can't use return 1, because a grep/map block is
kc:very consistent, IMHO: You just need to keep in mind the types of
kc:the values/data types ultimately being expressed, and it should
kc:become clearer. $ always prefixes scalars or references, @
kc:always prefixes lists, and % always prefixes associative arrays
kc:(a.k.a hashes).
kc:
kc:@array is a
Fliptop [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
[reply cc'd to list]
On Thu, 19 Dec 2002 at 06:23, Rob Richardson opined:
RR:What is the advantage of these changes?
RR:When is Perl 6 due out?
RR:Do those links you provided describe all the
Fliptop [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
[reply cc'd to list]
On Thu, 19 Dec 2002 at 06:23, Rob Richardson opined:
RR:What is the advantage of these changes?
RR:When is Perl 6 due out?
RR:Do those links you provided describe all the
And, for increased flexibility (strict/warn OK)
my @array = ( 10,20,30,40); my %array = @array;
my %hash = (1,2,3,4); my @hash = %hash;
print Array Element \$array[1] = $array[1]\n;
print Hash Element \$hash{'1'} = $hash{'1'}\n;
print Array Hash Element \$array{'10'} = $array{'10'}\n;
print
scalars or references, @
always prefixes lists, and % always prefixes associative arrays
(a.k.a hashes).
@array is a list
$array[n] is a scalar/reference
%hash is a hash
$hash{'key'} is a scalar/reference
@$ref dereferences a reference to an array, accessing the array In
this case, print $ref; would
being expressed, and it should
kc:become clearer. $ always prefixes scalars or references, @
kc:always prefixes lists, and % always prefixes associative arrays
kc:(a.k.a hashes).
kc:
kc:@array is a list
kc:$array[n] is a scalar/reference
kc:%hash is a hash
kc:$hash{'key'} is a scalar/reference
kc
[reply cc'd to list]
On Thu, 19 Dec 2002 at 06:23, Rob Richardson opined:
RR:What is the advantage of these changes?
RR:When is Perl 6 due out?
RR:Do those links you provided describe all the differences we will see in
RR:Perl 6?
i'm no authority on perl 6, so i can't answer any of your
@var is an array
$var is a scalar
$var[0] is also a scalar even though is an array element.
@var[0] is an array which contains more array elements, but in this case it
contains just a single element.
To create an array slice with more elements, you'll need something like
@var[0 .. n]
You need
I can see where you're coming from on this. However the most obvious reason is that
perl has no relationship in scalar context between @somename and %somename.
Your question regarding the special $ is not germane to this concept. Each element
of the array is a separate scalar variable, accessed
I don't know that I'd agree with the assessment
@ = ordered list
% = unordered list
That's a bit confusing. It's true that a hash (or associative array) uses
its own sort order unless you use the 'sort' option.
But an array is a simple list of elements, whereas a hash
77 matches
Mail list logo