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
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
*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
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
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!
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.
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
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'
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
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
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
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
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
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
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]+)
>
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
([^]+) \(([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.+)
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 =~ /^(.+):
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
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
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
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");
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
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
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
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
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
> "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
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
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
[ 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
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;
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
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 ]
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
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
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",
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
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):\/\/)?.+$/;
# ^
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
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):\/\/)?.+$/;
# ^
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
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
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:/
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 =
>
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
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
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
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
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
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
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
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:
53 matches
Mail list logo