> -Original Message-
> From: Emanuele Osimo [mailto:e.os...@gmail.com]
> Sent: Wednesday, July 22, 2009 15:47
> To: beginners perl ml
> Subject: Reading a list of numbers into an array
>
> Hello there, I'd like to read a file thet is a list of numbers like:
> 3084
> 4855
> 2904
> making e
On Jul 22, 2009, at 19:07, "Shawn H. Corey"
wrote:
Chas. Owens wrote:
#!/usr/bin/perl
use strict;
use warnings;
my $fakefile = "6754\r\n7890\r\n6543\r\n";
open my $fh, "<", \$fakefile
or die "could not open the fake file: $!";
open my $fh, '<:crlf', \$fakefile
or die "could not op
Hello,
the solution from John W. Krahn 'did the trick':
s!^.*/something_constant/[^/]+/!!;
Thank's a lot to John and Chas
Peter
> I've to cut off parts of an url like
> '/something_variable_1/something_constant/something_variable_2/something_va
>riable_3/filename'
>
> The result should be 'som
Chas. Owens wrote:
#!/usr/bin/perl
use strict;
use warnings;
my $fakefile = "6754\r\n7890\r\n6543\r\n";
open my $fh, "<", \$fakefile
or die "could not open the fake file: $!";
open my $fh, '<:crlf', \$fakefile
or die "could not open the fake file: $!";
my @array;
while (my
On Wed, Jul 22, 2009 at 18:04, Owen wrote:
snip
> It works for me. So try this
snip
Try this, it simulates what is probably happening:
#!/usr/bin/perl
use strict;
use warnings;
my $fakefile = "6754\r\n7890\r\n6543\r\n";
open my $fh, "<", \$fakefile
or die "could not open the fake file:
Emanuele Osimo wrote:
Hello there, I'd like to read a file thet is a list of numbers like:
3084
4855
2904
making each line (each number) one of the elements of the array. I've tried
foreach my $line (){ push (@array, $line) }
but then printing the array just gives me the last number, in this case
Thanks a lot!!
This is exactly what I needed!
Emanuele
On Wed, Jul 22, 2009 at 15:04, Wagner, David --- Senior Programmer Analyst
--- CFS wrote:
> > -Original Message-
> > From: Emanuele Osimo [mailto:e.os...@gmail.com]
> > Sent: Wednesday, July 22, 2009 15:47
> > To: beginners perl ml
>
> Hello there, I'd like to read a file thet is a list of numbers like:
> 3084
> 4855
> 2904
> making each line (each number) one of the elements of the array. I've
> tried
> foreach my $line (){ push (@array, $line) }
> but then printing the array just gives me the last number, in this
> case
> "2
On Wed, Jul 22, 2009 at 17:47, Emanuele Osimo wrote:
> Hello there, I'd like to read a file thet is a list of numbers like:
> 3084
> 4855
> 2904
> making each line (each number) one of the elements of the array. I've tried
> foreach my $line (){ push (@array, $line) }
> but then printing the array
Hello there, I'd like to read a file thet is a list of numbers like:
3084
4855
2904
making each line (each number) one of the elements of the array. I've tried
foreach my $line (){ push (@array, $line) }
but then printing the array just gives me the last number, in this case
"2904".
What's wrong?
On Wed, Jul 22, 2009 at 12:11, Bryan R
Harris wrote:
snip
> If your arrays could be very large, it's a waste of cycles to sort the list
> then throw most of that effort away. You could do:
snip
Due to the fact that sort is written in C, it can be faster to sort
than to loop over the array in Perl
Mallya, Vaibhav U wrote:
Hi All,
Hello,
I need to used some perl code in k and C shell. But it is giving me bad
substitution. Same code works fine in bash. Any help would be
appreciated.
perl -i -e '$re=q~'${1//~/\\~}'~; print "$re"; while (<>) { /$re/ ? $c++
: print;}exit($c ? 0 : 1)' /home
On Wed, Jul 22, 2009 at 03:30, sheela b wrote:
> Hi Jenn,
>
> You can fing max and min value as,
>
> my @ar = (1,2,3,4,58,9,2,1);
> my $max = (sort { $b <=> $a } @ar)[0];
> my $min = (sort { $a <=> $b } @ar)[0];
snip
This is only efficient up to about 250 values in @ar, if @ar is going
to have mor
> You can fing max and min value as,
>
> my @ar = (1,2,3,4,58,9,2,1);
> my $max = (sort { $b <=> $a } @ar)[0];
> my $min = (sort { $a <=> $b } @ar)[0];
If your arrays could be very large, it's a waste of cycles to sort the list
then throw most of that effort away. You could do:
**
Surprising it works with bash at all.
For the shell, your string is: '$re=q~', and the rest is no longer escaped.
HTH,
-- Eric
From: "Mallya, Vaibhav U"
Hi All,
I need to used some perl code in k and C shell. But it is giving me bad
substitution. Same code works fine in bash. Any help would be
appreciated.
perl -i -e '$re=q~'${1//~/\\~}'~; print "$re"; while (<>) { /$re/ ? $c++
: print;}exit($c ? 0 : 1)' /home/vmallya/testing || echo " Delete of
l
> -Original Message-
> From: Patrick K Christopher TANAGER
> [mailto:pchristop...@tanagerinc.com]
> Sent: Tuesday, July 21, 2009 11:04
> To: Wagner, David --- Senior Programmer Analyst --- CFS; Tony
> Esposito; beginners@perl.org
> Subject: RE: Having problems getting data back to STDOUT
thanks all the suggestions.
On Wed, Jul 22, 2009 at 4:32 PM, Shawn H. Corey wrote:
> Jenn G. wrote:
>>
>> Hello,
>>
>> How to lookup the max and min value in an array?
>> Just like SQL's max() and min() functions.
>>
>> Thanks.
>>
>
> use List::Util qw/min max/;
>
> See `perldoc List::Util` for de
Jenn G. wrote:
Hello,
How to lookup the max and min value in an array?
Just like SQL's max() and min() functions.
Thanks.
use List::Util qw/min max/;
See `perldoc List::Util` for details.
--
Just my 0.0002 million dollars worth,
Shawn
Programming is as much about organization and c
Hi Jenn,
You can fing max and min value as,
my @ar = (1,2,3,4,58,9,2,1);
my $max = (sort { $b <=> $a } @ar)[0];
my $min = (sort { $a <=> $b } @ar)[0];
Regards
Sheela
On Wed, Jul 22, 2009 at 12:48 PM, Jenn G. wrote:
> Hello,
>
> How to lookup the max and min value in an array?
> Just like SQL's
Hello,
How to lookup the max and min value in an array?
Just like SQL's max() and min() functions.
Thanks.
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/
21 matches
Mail list logo