RE: Reading a list of numbers into an array

2009-07-22 Thread Wagner, David --- Senior Programmer Analyst --- CFS
> -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

Re: Reading a list of numbers into an array

2009-07-22 Thread Chas. Owens
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

Re: [solved] How to cut off parts of an url

2009-07-22 Thread Peter
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

Re: Reading a list of numbers into an array

2009-07-22 Thread Shawn H. Corey
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

Re: Reading a list of numbers into an array

2009-07-22 Thread Chas. Owens
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:

Re: Reading a list of numbers into an array

2009-07-22 Thread Shawn H. Corey
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

Re: Reading a list of numbers into an array

2009-07-22 Thread Emanuele Osimo
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 >

Re: Reading a list of numbers into an array

2009-07-22 Thread Owen
> 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

Re: Reading a list of numbers into an array

2009-07-22 Thread Chas. Owens
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

Reading a list of numbers into an array

2009-07-22 Thread Emanuele Osimo
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?

Re: evaluate for max and min value in array

2009-07-22 Thread Chas. Owens
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

Re: Using perl code in K and C shell

2009-07-22 Thread John W. Krahn
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

Re: evaluate for max and min value in array

2009-07-22 Thread Chas. Owens
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

Re: evaluate for max and min value in array

2009-07-22 Thread Bryan R Harris
> 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: **

Re: Using perl code in K and C shell

2009-07-22 Thread Eric Veith
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"

Using perl code in K and C shell

2009-07-22 Thread 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

RE: Having problems getting data back to STDOUT once I assign it to a file

2009-07-22 Thread Wagner, David --- Senior Programmer Analyst --- CFS
> -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

Re: evaluate for max and min value in array

2009-07-22 Thread Jenn G.
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

Re: evaluate for max and min value in array

2009-07-22 Thread Shawn H. Corey
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

Re: evaluate for max and min value in array

2009-07-22 Thread sheela b
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

evaluate for max and min value in array

2009-07-22 Thread Jenn G.
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/