Re: small puzzle

2014-04-27 Thread Harry Putnam
Shawn H Corey writes: > On Fri, 25 Apr 2014 12:39:21 -0700 > John SJ Anderson wrote: > >> Perl doesn't charge you by the lines of code you use, so doing this: >> >>my $re = shift; >>$re = qr/$re/; >> >> is just fine. > > This also works: > > my $re = qr/$ARGV[0]/; > shift @ARGV

Re: small puzzle

2014-04-27 Thread Harry Putnam
Uri Guttman writes: > On 04/25/2014 12:55 PM, Harry Putnam wrote: >> Uri Guttman writes: >> >>> why would you expect anything but 1 as the value? shift will return 1 >>> value or undef. that anon array will be dereferenced to an array with >>> 1 entry. the array is in scalar context which return

Re: small puzzle

2014-04-25 Thread John SJ Anderson
*puts on List Mom hat* Okay, we're done here. The original question was asked and answered (a couple times). Let's move on and get back to dealing with Perl questions, not personalities. thanks, john. *takes List Mom hat back off* -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For a

Re: small puzzle

2014-04-25 Thread Rob Dixon
On 26/04/2014 02:16, Uri Guttman wrote: On 04/25/2014 12:55 PM, Harry Putnam wrote: Uri Guttman writes: why would you expect anything but 1 as the value? shift will return 1 value or undef. that anon array will be dereferenced to an array with 1 entry. the array is in scalar context which ret

Re: small puzzle

2014-04-25 Thread Uri Guttman
On 04/25/2014 12:55 PM, Harry Putnam wrote: Uri Guttman writes: why would you expect anything but 1 as the value? shift will return 1 value or undef. that anon array will be dereferenced to an array with 1 entry. the array is in scalar context which returns its size. elementary!

Re: small puzzle

2014-04-25 Thread Shawn H Corey
On Fri, 25 Apr 2014 12:39:21 -0700 John SJ Anderson wrote: > Perl doesn't charge you by the lines of code you use, so doing this: > >my $re = shift; >$re = qr/$re/; > > is just fine. This also works: my $re = qr/$ARGV[0]/; shift @ARGV; -- Don't stop where the ink does.

Re: small puzzle

2014-04-25 Thread John SJ Anderson
On Fri, Apr 25, 2014 at 12:18 PM, Harry Putnam wrote: > About just using 'shift': How I happened to be using that weird > looking notation at all was because I thought it was a way to avoid > the extra step of compiling the rgx in qr// after shifting. My advice to you on this point would be tha

Re: small puzzle

2014-04-25 Thread Harry Putnam
John SJ Anderson writes: > In general, anywhere you're doing '@{[shift]}', unless you REALLY know > what's going on and why you'd want to do that ... instead just do > 'shift'. Thanks for the in depth answer. Very helpful. You've helped fill some tragic holes in my basic knowledge of perl. I'

Re: small puzzle

2014-04-25 Thread Harry Putnam
Uri Guttman writes: > why would you expect anything but 1 as the value? shift will return 1 > value or undef. that anon array will be dereferenced to an array with > 1 entry. the array is in scalar context which returns its > size. elementary! ^ my dear Watson. Thank you Mr U

Re: small puzzle

2014-04-24 Thread Uri Guttman
On 04/24/2014 11:40 PM, Harry Putnam wrote: Some simple code that is similar to other code I've written and used is returning something I don't understand. I've used the notation below for shifting off elements of AR many times but don't recall seeing this output. I think I know what is happeni

Re: small puzzle

2014-04-24 Thread John SJ Anderson
On Thu, Apr 24, 2014 at 8:40 PM, Harry Putnam wrote: > my $dir2sr = @{[shift]}; This shifts an element off @ARGV, makes an array reference containing a single element (the value that was just shifted off), then deferences that arrayref to create an array (which still contains a single element, t

small puzzle

2014-04-24 Thread Harry Putnam
Some simple code that is similar to other code I've written and used is returning something I don't understand. I've used the notation below for shifting off elements of AR many times but don't recall seeing this output. I think I know what is happening but I don't understand why. Is the second

Re: regexp puzzle

2014-03-08 Thread Bill McCormick
On 3/8/2014 12:05 AM, Bill McCormick wrote: I have the following string I want to extract from: my $str = "foo (3 bar): baz"; and I want to to extract to end up with $p1 = "foo"; $p2 = 3; $p3 = "baz"; the complication is that the \s(\d\s.+) is optional, so in then $p2 may not be set. getting

Re: regexp puzzle

2014-03-07 Thread Jim Gibson
On Mar 7, 2014, at 10:05 PM, Bill McCormick wrote: > I have the following string I want to extract from: > > my $str = "foo (3 bar): baz"; > > and I want to to extract to end up with > > $p1 = "foo"; > $p2 = 3; > $p3 = "baz"; > > the complication is that the \s(\d\s.+) is optional, so in the

Re: regexp puzzle

2014-03-07 Thread shawn wilson
On Mar 8, 2014 1:41 AM, "shawn wilson" wrote: > Oh and per optional, just do (?:\([0-9]+).*\)? You should probably use do my @match = $str =~ / ([^]+) (?:\([0-9]+).*\)? ([a-z]+)/; my ($a, $b, $c) = (scalar(@match) == 3 ? @match : $match[0], undef, $match[1]); > ([^]+) \(([0-9]+).*\) ([a-z]+) >

Re: regexp puzzle

2014-03-07 Thread Bill McCormick
On 3/8/2014 12:41 AM, shawn wilson wrote: my $str = "foo (3 bar): baz"; my $test = "foo (3 bar): baz"; my ($p1, $p2, $p3) = $test =~ /([^]+) \(([0-9]+).*\) ([a-z]+)/; print "p1=[$p1] p2=[$p2] p3=[$p3]\n"; Use of uninitialized value $p1 in concatenation (.) or string at ./lock_report.pl line 1

Re: regexp puzzle

2014-03-07 Thread shawn wilson
([^]+) \(([0-9]+).*\) ([a-z]+) On Mar 8, 2014 1:07 AM, "Bill McCormick" wrote: > I have the following string I want to extract from: > > my $str = "foo (3 bar): baz"; > > and I want to to extract to end up with > > $p1 = "foo"; > $p2 = 3; > $p3 = "baz"; > > the complication is that the \s(\d\s.+)

regexp puzzle

2014-03-07 Thread Bill McCormick
I have the following string I want to extract from: my $str = "foo (3 bar): baz"; and I want to to extract to end up with $p1 = "foo"; $p2 = 3; $p3 = "baz"; the complication is that the \s(\d\s.+) is optional, so in then $p2 may not be set. getting close was my ($p1, $p3) = $str =~ /^(.+):

Re: list to hash puzzle

2014-02-10 Thread Dr.Ruud
On 2014-02-09 17:48, Bill McCormick wrote: Trying to map the array list into a hash, but loose the double quotes surrounding the key's value. Or do str-to-hash: perl -Mstrict -MData::Dumper -wE' my $str = q(foo1="bar1" foo2="bar2"); my $re_kv = qr/\s*(\S+)\s*=\s*"([^"]*)"/; my %hash

Re: list to hash puzzle

2014-02-09 Thread shawn wilson
Ugh, best document the hell out of that. Split with parameters, splitting a tr - I see that everywhere... On Feb 9, 2014 6:45 PM, "Bill McCormick" wrote: > On 2/9/2014 10:48 AM, Bill McCormick wrote: > >> Trying to map the array list into a hash, but loose the double quotes >> surrounding the key

Re: list to hash puzzle

2014-02-09 Thread Shawn H Corey
On Sun, 09 Feb 2014 16:29:30 -0600 Bill McCormick wrote: > On 2/9/2014 3:58 PM, Shawn H Corey wrote: > > On Sun, 09 Feb 2014 10:48:46 -0600 > > Bill McCormick wrote: > > > >> Trying to map the array list into a hash, but loose the double > >> quotes surrounding the key's value. > > > > You can c

Re: list to hash puzzle

2014-02-09 Thread Bill McCormick
On 2/9/2014 10:48 AM, Bill McCormick wrote: Trying to map the array list into a hash, but loose the double quotes surrounding the key's value. This is close, but it's not removing the quotes. Solutions? #!/usr/bin/perl -w use strict; use Data::Dumper; my @array = qw(foo1="bar1" foo2="bar2");

Re: list to hash puzzle

2014-02-09 Thread Uri Guttman
On 02/09/2014 05:29 PM, Bill McCormick wrote: On 2/9/2014 3:58 PM, Shawn H Corey wrote: On Sun, 09 Feb 2014 10:48:46 -0600 Bill McCormick wrote: Trying to map the array list into a hash, but loose the double quotes surrounding the key's value. You can convert a list to a hash directly: my

Re: list to hash puzzle

2014-02-09 Thread Andy Bach
On Sun, Feb 9, 2014 at 10:48 AM, Bill McCormick wrote: > Trying to map the array list into a hash, but loose the double quotes > surrounding the key's value. "lose" the quotes, you mean. I think the trouble is your thinking the map will create a list of strings and so the quotes will auto-magic

Re: list to hash puzzle

2014-02-09 Thread Bill McCormick
On 2/9/2014 3:58 PM, Shawn H Corey wrote: On Sun, 09 Feb 2014 10:48:46 -0600 Bill McCormick wrote: Trying to map the array list into a hash, but loose the double quotes surrounding the key's value. You can convert a list to a hash directly: my %hash = qw( foo1 bar1 foo2 bar2 ); Sure, bu

Re: list to hash puzzle

2014-02-09 Thread Shawn H Corey
On Sun, 09 Feb 2014 10:48:46 -0600 Bill McCormick wrote: > Trying to map the array list into a hash, but loose the double quotes > surrounding the key's value. You can convert a list to a hash directly: my %hash = qw( foo1 bar1 foo2 bar2 ); -- Don't stop where the ink does. Shawn

list to hash puzzle

2014-02-09 Thread Bill McCormick
Trying to map the array list into a hash, but loose the double quotes surrounding the key's value. This is close, but it's not removing the quotes. Solutions? #!/usr/bin/perl -w use strict; use Data::Dumper; my @array = qw(foo1="bar1" foo2="bar2"); print "Array:\n"; print Dumper(@array); pr

Re: Benchmark puzzle

2010-11-11 Thread Uri Guttman
> "MM" == Mike McClain writes: MM> Thinking the number of inerations of the benchmark loop might be MM> low enough to affect the results I doubled it and reran the above MM> command. a good trick when using benchmark is to support a command line arg to set the iteration count with a de

Benchmark puzzle

2010-11-11 Thread Mike McClain
Hello List, A posting about splitting a string into n numbered groups of characters led me to write a short script exploring the ways to do so. Later I got to wondering how the various approaches compared so added benchmarking code. Last week I ran the script, made a minor cosmetic change and r

Re: puzzle

2010-04-07 Thread Paul Johnson
On Mon, Apr 05, 2010 at 08:55:39AM -0700, ubuntu wrote: > Hi > > I am new in perl script. Does anyone know how to implement this puzzle > in perl? > > [ 0 ]= 0 > [ 1 ]= 1 > [ 0, 1 ] = 1 > [ 1, 1

Re: puzzle

2010-04-07 Thread Rafal Czlonka
[ 2 ], [ 3 ] ] = -4 > > [ 9, [ 3, 4, [ [ 2 ] ] ] ] = 0 > > ... > > > > I know how to implement arrays that contain array references (in case that's > what you want) but I don't understand the logic behind this puzzle. Please > detail its

Re: puzzle

2010-04-07 Thread Dr.Ruud
Harinatha Reddy M wrote: For example: [ 9, [ 3, 4, [ [ 2 ] ] ] ] = 0 In this case we need to fnid the sum of 9, [3,4, [[2]]] So if we look at it in the equation format 9+ (-(3+4+ -(-(2 i.e 9+ (-(3+4+2)) = 9+ (-(9)) = 9-9 = 0 echo "[ 1, [ 2 ], [ 3 ] ]" | perl -ne' chomp; print;

Re: puzzle

2010-04-06 Thread Harinatha Reddy M
I got to know how to solve the puzzle. We need to find the sum of elements encovered by the outer array. And once we enter the elemnets, whenever we find an element enclosed by [x] we shoudl take that as -x for the summation. For example: [ 9, [ 3, 4, [ [ 2 ] ] ] ] = 0 In this case we need

Re: puzzle

2010-04-06 Thread Shlomi Fish
etdance.com/Stop_saying_%22script%22 * http://www.perl.com/pub/a/2007/12/06/soto-11.html - "Programming is Hard. Let's Go Scripting" - by Larry Wall. > Does anyone know how to implement this puzzle > in perl? > > [ 0 ]= 0 > [ 1 ]

puzzle

2010-04-06 Thread ubuntu
Hi I am new in perl script. Does anyone know how to implement this puzzle in perl? [ 0 ]= 0 [ 1 ]= 1 [ 0, 1 ] = 1 [ 1, 1 ] = 2 [ 1, [ 1, 2 ] ] = -2 [ 1, 2, [ 8 ] ] = -5 [ 1, [ 2

Re: Puzzle: Know Your Data

2005-08-12 Thread Graeme St.Clair
depended on whether 'use locale' was included. Looking forward to the answer, GStC. - Original Message - From: "Ugly Virgin" <[EMAIL PROTECTED]> To: "Jeff 'japhy' Pinyan" <[EMAIL PROTECTED]> Cc: Sent: Friday, August 12, 2005 1

Re: Puzzle: Know Your Data

2005-08-12 Thread Ugly Virgin
ays AREN'T IDENTICAL. The puzzle to you is to determine the reason and sample data that demonstrates the problem. one possible answer: symbols in the data (specifically the ones between the upper and lower case characters in ASCII) $ perl -le'$,="\n";@a=("Hello",

Puzzle: Know Your Data

2005-08-12 Thread Jeff 'japhy' Pinyan
sort { lc($a) cmp lc($b) } @data; And then later in your code, forgetting how you'd done it before, you use: # convert the strings to uppercase when comparing my @ordered = sort { uc($a) cmp uc($b) } @data; But this gives you a headache: the arrays AREN'T IDENTICAL. The puzz

Re: regex puzzle

2005-07-29 Thread Tom Allison
Roberto Ruiz wrote: On Fri, Jul 29, 2005 at 01:48:15PM +0800, bingfeng zhao wrote: See following sample code: my @address = ("http://test";, "http://";, "www", "", "ftp:/foo" ); for (@address) { print "\"$_\" passed! \n" if /^((http|ftp):\/\/)?.+$/; # ^

Re: regex puzzle

2005-07-29 Thread Pedro Henrique Calais
ED]> To: Sent: Friday, July 29, 2005 6:52 AM Subject: Re: regex puzzle On Fri, Jul 29, 2005 at 01:48:15PM +0800, bingfeng zhao wrote: See following sample code: my @address = ("http://test";, "http://";, "www

Re: regex puzzle

2005-07-29 Thread Roberto Ruiz
On Fri, Jul 29, 2005 at 01:48:15PM +0800, bingfeng zhao wrote: > See following sample code: > > my @address = ("http://test";, "http://";, "www", "", "ftp:/foo" ); > > for (@address) > { > print "\"$_\" passed! \n" if /^((http|ftp):\/\/)?.+$/; # ^

Re: regex puzzle

2005-07-29 Thread Flemming Greve Skovengaard
bingfeng zhao wrote: See following sample code: use warnings; use strict; my @address = ("http://test";, "http://";, "www", "", "ftp:/foo" ); for (@address) { print "\"$_\" passed! \n" if /^((http|ftp):\/\/)?.+$/; } the running result is: "http://test"; is valid. "http://"; is vali

RE: regex puzzle

2005-07-29 Thread bingfeng zhao
age- |From: bingfeng zhao [mailto:[EMAIL PROTECTED] |Sent: Friday, July 29, 2005 1:48 PM |To: Perl Beginners List |Subject: regex puzzle | |See following sample code: | | |use warnings; |use strict; | |my @address = ("http://test";, "http://";, "www", "&quo

regex puzzle

2005-07-28 Thread bingfeng zhao
See following sample code: use warnings; use strict; my @address = ("http://test";, "http://";, "www", "", "ftp:/foo" ); for (@address) { print "\"$_\" passed! \n" if /^((http|ftp):\/\/)?.+$/; } the running result is: "http://test"; is valid. "http://"; is valid. "www" is valid. "ftp:/

RE: 'format' puzzle

2005-04-14 Thread Sam
Thanks. Was right there in the manual... -Sam --- "Moon, John" <[EMAIL PROTECTED]> wrote: > Subject: 'format' puzzle > > How can I create a perl 'format' string that begins with a comment (#)? > > Eg. > > format STDOUT_TOP = >

RE: 'format' puzzle

2005-04-14 Thread Moon, John
Subject: 'format' puzzle How can I create a perl 'format' string that begins with a comment (#)? Eg. format STDOUT_TOP = # Field1 Field2 @<< @||| @||| . If I try '\#' then I see the backslash. I just want the pound char. TIA, -Sam I'm not

'format' puzzle

2005-04-13 Thread Sam
How can I create a perl 'format' string that begins with a comment (#)? Eg. format STDOUT_TOP = # Field1 Field2 @<< @||| @||| . If I try '\#' then I see the backslash. I just want the pound char. TIA, -Sam __ Do you Yahoo!? Yaho

Re: [OT] math puzzle

2001-11-27 Thread Etienne Marcotte
Well my english isn't good enough I meant the oldest meaning there was only ONE oldest so it's 2,2,9 Because it was too easy if there were 2 oldests.. only combinaison would be 1,6,6 Anyways, it was pure logic.. find all possibilities of 3 ages that gives 36. keep the two with the same total (1

[OT] math puzzle

2001-11-26 Thread Jeff 'japhy' Pinyan
On Nov 26, Jeff 'japhy' Pinyan said: >>Mr.Foo: What's the age of your children Mr. Bar? >>Mr.Bar: I have 3 children, the multiplication of their ages is 36. >>Mr.Foo: This doesn't help very much. >>Mr.Bar: Well if you add their 3 ages, you get the number fo windows in >>my house. >>Mr.Foo: I know

Re: Another regex puzzle....

2001-07-25 Thread Jeff 'japhy/Marillion' Pinyan
On Jul 25, Hamish Whittal said: >%CardType% .1.3.6.1.4.1.45.1.6.3.3.1.1.5 >%CardSlotNum% =calc=CardType/3.([0-9]*).0/ >if ( /^%([a-zA-Z]*)%[\s\t]*[\=calc\=([a-zA-Z]+)\/(.*)\/|(\.[0-9]*)]/ ) { I'm afraid you're trying to be a bit too specific. If you let yourself slip in

Another regex puzzle....

2001-07-25 Thread Hamish Whittal
Hello all, here I go again with another reegex problem. I have the following in a conf file: %CardType% .1.3.6.1.4.1.45.1.6.3.3.1.1.5 %CardSlotNum% =calc=CardType/3.([0-9]*).0/ Now what I'm wanting to do is get the card type (using SNMP). Then to calculate the slot numbe

RE: Another puzzle......??

2001-05-15 Thread Peter Cornelius
With minimal quoting >I have a line that looks like this: > > TOXFY-1 LENDER: DISBURSEMENT DATE: RUN DATE: 05/01/2001 > >I want to pull off the 1st field and the date. How about ($first, $last) = (split /\s+/, $_)[0,-1]; This will give you the first and last entries

Another puzzle......??

2001-05-15 Thread Gary Luther
Thanks to all who responded to previous query. Hopefully I will someday be a better Perl programmer for it.   Now on to another perplexing problem   I have a line that looks like this:    TOXFY-1   LENDER:    DISBURSEMENT DATE: