[30902] in Perl-Users-Digest
Perl-Users Digest, Issue: 2147 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 22 00:09:45 2009
Date: Wed, 21 Jan 2009 21:09:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 21 Jan 2009 Volume: 11 Number: 2147
Today's topics:
ANNOUNCEMENT: ModBox - Open Platform as a Service <brian@glamourati.com>
Re: CGI.pm and Use of uninitialized value in pattern ma <glennj@ncf.ca>
Re: CGI.pm and Use of uninitialized value in pattern ma <noreply@gunnar.cc>
How can I use a REGEX to process WORDS spydox@gmail.com
Re: How can I use a REGEX to process WORDS <steve.roscio@hp.com>
Re: How can I use a REGEX to process WORDS <1usa@llenroc.ude.invalid>
Re: inputting the ephemerides <larry@example.invalid>
Re: inputting the ephemerides <larry@example.invalid>
Re: inputting the ephemerides <tadmc@seesig.invalid>
Re: inputting the ephemerides <jurgenex@hotmail.com>
Re: Match CASE/END SQL Construct sln@netherlands.com
Re: on Code references <ced@blv-sam-01.ca.boeing.com>
Re: on Code references <whynot@pozharski.name>
Re: What do you need to have to be considered a Master <rvtol+usenet@xs4all.nl>
Re: What do you need to have to be considered a Master <xhoster@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 21 Jan 2009 20:24:31 -0800 (PST)
From: ModBox <brian@glamourati.com>
Subject: ANNOUNCEMENT: ModBox - Open Platform as a Service
Message-Id: <3e628972-a15f-464a-a56d-58f1b6f9114e@k9g2000vbl.googlegroups.com>
ModBox an "Open Platform as a Service" (OPaaS). Ok, what the #@#$ is
OPaaS? OPaaS is PaaS, but open. Think Force.com/Google App Engine/
Amazon EC2 - but open. Really open. Not fake open like so much other
BS services that try to lock you in. In a nutshell, ModBox is a Web-
based distributed development environment that is completely neutral
in every way. So, you can use any infrastructure you want, any
programming language, (e.g., Perl, Ruby on Rails, PHP, Java, etc.) any
server, any OS, any database, etc. to create/distribute applications.
Also, because ModBox works over standard HTTP, you can incorporate
existing applications or web services into the applications you
create. ModBox brings all the pieces together seemlessly for
programmers and users. I hope I have borrowed the best ideas from
IDE's, RAD, frameworks, Web services grid/cloud computing and Open
Source to make a logical ecosystem which puts a much needed front-end/
face on all of it. Being a programmer, I know getting programmers
interested in a new service is key, or as an old friend of mine used
to say, ignore the programmers and die! With that said, I welcome you
to Rock the Box and let me know if it makes as much sense to you as it
does to me. I
would, of course greatly appreciate any feedback as I am not so bold
to think I have cracked the code on the 1.0. The URL is below.
ModBox - Open Platform as a Service:
http://www.sullivansoftwaresystems.com/modbox
Thanks for your time.
Brian Sullivan
Sullivan Software Systems
ModBox - Rock the Box.
------------------------------
Date: 21 Jan 2009 22:08:49 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: CGI.pm and Use of uninitialized value in pattern match
Message-Id: <slrngnf77j.m06.glennj@smeagol.ncf.ca>
At 2009-01-21 09:27AM, "A. Farber" wrote:
> Hello Perl users,
>
> I have a habit of untainting input data this way in my
> CGI scripts (example: http://pastebin.com/m46057a70):
>
> $user = $1 if $query->param('user') =~ /(\w{3,12})/;
> $pass = $1 if $query->param('pass') =~ /(\w{8})/;
> .....
> unless ($user and $pass and ...) {
> print $query->start_form(), ...
> } else {
> # do the real work with untainted data
> }
I would start with:
unless ($query->param()) {
# first visit, show the form
emit_into_page();
exit;
}
# validate
my ($user, $pass);
if (defined $query->param('user') and $query->param('user') =~ /(...)/) {
$user = $1;
}
if (defined $query->param('pass') and $query->param('pass') =~ /(...)/) {
$pass = $1;
}
unless ($user and $pass) {
emit_error_page();
exit;
}
# do the real work...
--
Glenn Jackman
Write a wise saying and your name will live forever. -- Anonymous
------------------------------
Date: Thu, 22 Jan 2009 02:50:14 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: CGI.pm and Use of uninitialized value in pattern match
Message-Id: <6tq1qjFc417qU1@mid.individual.net>
A. Farber wrote:
> Gunnar Hjalmarsson wrote:
>> If the form include input controls named "user" respective "pass", those
>> parameters are always defined whether the fields were filled or not.
>> Consequently I don't understand the problem in the first place.
>
> I ... don't assume my script will be called from my web-form only.
Me neither. Of course. Just thought you might be interested in getting a
hint when someone posts to it from somewhere else.
> And also when the script is called for the 1st time, then those params
> aren't defined
Aha, so the form is generated by the same script. Now even I understand. :)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 21 Jan 2009 13:33:15 -0800 (PST)
From: spydox@gmail.com
Subject: How can I use a REGEX to process WORDS
Message-Id: <449a577f-1721-4f94-ac73-2717c8cb1e37@m12g2000vbp.googlegroups.com>
I often find that I need to make a change to a block with logic like:
IN ALL START APPLE..END APPLE blocks, change NUMBER N to NUMBER N+1 if
the color is RED
Using a regex to do this seems impractical to me ( and perhaps it
really is), so in these WORD-ish cases I usually just loop through the
array lines and set flags like $inAPPLE++... Its also tricky because
often as in this case, I have to *look ahead* to check the color.
Which makes looping not so nifty either.
What I'd really prefer is a regex that sensed when I was in a START
APPLE..END APPLE clause (of course ONLY in one clause- not the very
FIRST START APPLE to the very LAST END APPLE), then
Another approach I sometimes take is to split() the blocks out, then
map the regex into the split array, then recombine. That's actually
usually pretty effective, but sort of a pain because I have to
scalarize the array, split it, map it, recombine it, and then re-array
it. Geesh!
So anyhow- I'm just wondering if this is some sort of perfunc or regex
etc I can use to assist? I feel like I'm barking up the wrong tree..
Thanks in advance gurus..
!
START APPLE
.
.
NUMBER 5
COLOR RED
.
.
END APPLE
.
!
START ORANGE
.
.
NUMBER 10
COLOR GREEN
.
END ORANGE
.
.
!
START APPLE
.
.
NUMBER 10
COLOR GREEN
.
.
END APPLE
!
START APPLE
.
.
NUMBER 2
COLOR RED
.
.
END APPLE
------------------------------
Date: Wed, 21 Jan 2009 14:56:22 -0700
From: Steve Roscio <steve.roscio@hp.com>
Subject: Re: How can I use a REGEX to process WORDS
Message-Id: <gl85m7$q1a$1@usenet01.boi.hp.com>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Is this along the lines of what you're looking for?
$a = ... #your big blob of fruit text
$fruit = "apple";
$color = "red";
@clauses = $a =~ m{start \s+ $fruit
((?: .*? ) \b color \s+ $color (?: .*? )) \b
end \s $fruit
}ixg;
In the above @clauses will contain all inner clauses that match the
fruit and color given. I know this doesn't address the substitution
part of your problem, but lets take it a step at a time... (I'm not
sure I understand your problem fully).
- - Steve
spydox@gmail.com wrote:
> I often find that I need to make a change to a block with logic like:
>
> IN ALL START APPLE..END APPLE blocks, change NUMBER N to NUMBER N+1 if
> the color is RED
>
> Using a regex to do this seems impractical to me ( and perhaps it
> really is), so in these WORD-ish cases I usually just loop through the
> array lines and set flags like $inAPPLE++... Its also tricky because
> often as in this case, I have to *look ahead* to check the color.
> Which makes looping not so nifty either.
>
> What I'd really prefer is a regex that sensed when I was in a START
> APPLE..END APPLE clause (of course ONLY in one clause- not the very
> FIRST START APPLE to the very LAST END APPLE), then
>
> Another approach I sometimes take is to split() the blocks out, then
> map the regex into the split array, then recombine. That's actually
> usually pretty effective, but sort of a pain because I have to
> scalarize the array, split it, map it, recombine it, and then re-array
> it. Geesh!
>
> So anyhow- I'm just wondering if this is some sort of perfunc or regex
> etc I can use to assist? I feel like I'm barking up the wrong tree..
> Thanks in advance gurus..
>
> !
> START APPLE
> .
> .
> NUMBER 5
> COLOR RED
> .
> .
> END APPLE
> .
> !
> START ORANGE
> .
> .
> NUMBER 10
> COLOR GREEN
> .
> END ORANGE
> .
> .
> !
> START APPLE
> .
> .
> NUMBER 10
> COLOR GREEN
> .
> .
>
> END APPLE
> !
> START APPLE
> .
> .
> NUMBER 2
> COLOR RED
> .
> .
> END APPLE
>
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkl3mf0ACgkQb3tX8F/f+Wy3YQCffjXyYzfO/+gUAJ5CPao7RlVZ
sLgAn1ef/R6D+fQgJyw7tYU8gdM6m1WQ
=3VLf
-----END PGP SIGNATURE-----
------------------------------
Date: Wed, 21 Jan 2009 22:22:00 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: How can I use a REGEX to process WORDS
Message-Id: <Xns9B9AB0A86548Fasu1cornelledu@127.0.0.1>
spydox@gmail.com wrote in news:449a577f-1721-4f94-ac73-2717c8cb1e37
@m12g2000vbp.googlegroups.com:
> I often find that I need to make a change to a block with logic like:
>
> IN ALL START APPLE..END APPLE blocks, change NUMBER N to NUMBER N+1 if
> the color is RED
>
> Using a regex to do this seems impractical to me ( and perhaps it
> really is), so in these WORD-ish cases I usually just loop through the
> array lines and set flags like $inAPPLE++... Its also tricky because
> often as in this case, I have to *look ahead* to check the color.
> Which makes looping not so nifty either.
>
> What I'd really prefer is a regex that sensed when I was in a START
> APPLE..END APPLE clause (of course ONLY in one clause- not the very
> FIRST START APPLE to the very LAST END APPLE), then
>
> Another approach I sometimes take is to split() the blocks out, then
> map the regex into the split array, then recombine. That's actually
> usually pretty effective, but sort of a pain because I have to
> scalarize the array, split it, map it, recombine it, and then re-array
> it. Geesh!
>
> So anyhow- I'm just wondering if this is some sort of perfunc or regex
> etc I can use to assist? I feel like I'm barking up the wrong tree..
> Thanks in advance gurus..
I am not sure anything is really wrong with the approaches listed above.
I would be inclined to parse the data into proper Perl data structures
(in this case an array of hashrefs seems reasonable). However, it seems
to me like you are not familiar with the range operator .. so I came up
with the following example using your data:
#!/usr/bin/perl
use strict;
use warnings;
my ($number, $color, $buffer);
while ( <DATA> ) {
print and next unless my $seq = /^START APPLE/ .. /^END APPLE/;
$buffer .= $_;
$number = $1 if /^NUMBER (\d+)/;
$color = $1 if /^COLOR (\w+)/;
if ( $seq =~ /E0$/ ) {
if ( $color eq 'RED') {
my $replacement = $number + 1;
$buffer =~ s/^NUMBER $number/NUMBER $replacement/m;
}
print $buffer;
undef for $number, $color, $buffer;
}
}
__DATA__
!
START APPLE
.
.
NUMBER 5
COLOR RED
.
.
END APPLE
.
!
START ORANGE
.
.
NUMBER 10
COLOR GREEN
.
END ORANGE
.
.
!
START APPLE
.
.
NUMBER 10
COLOR GREEN
.
.
END APPLE
!
START APPLE
.
.
NUMBER 2
COLOR RED
.
.
END APPLE
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
------------------------------
Date: Wed, 21 Jan 2009 17:40:32 -0700
From: Larry Gates <larry@example.invalid>
Subject: Re: inputting the ephemerides
Message-Id: <1mttg9gw20gpy$.17z9sqzzk6htd$.dlg@40tude.net>
On Wed, 21 Jan 2009 13:01:25 -0800, Jim Gibson wrote:
> You are actually having trouble extracting '6' from '6m' with (\d{2}),
> which causes all of your other matches to shift up one. You are better
> off matching a string of digits with (\d+), rather than insisting upon
> a specific number. If not, you should use (\d{1,2}).
Thanks, Jim, that puts me back on track.
My next hard match is 59.3' ,as in:
Mercury 20h 36m 41s -16 59.3'
What I have is *(\d{1,2}\.\d{1}) No amount of mixing symbols worked on
this one.
There's also trouble with the moon, as it has an extra ER that the others
don't have. This is the current script:
my $filename = 'eph6.txt';
open(my $fh, '<', $filename) or die "cannot open $filename: $!";
while (<$fh>) {
/(\w+)\W+(\d{1,2}).*?(\d{1,2}).*?(\d{1,2}).*?([-+]\d{1,2}).*(\d{1,2}\.\d{1})/;
print "string one is $1\n";
print "string two is $2\n";
print "string three is $3\n";
print "string four is $4\n";
print "string five is $5\n";
print "string six is $6\n";
print "string seven is $7\n";
print $_;
}
close($fh)
# perl faulk16.pl
C:\MinGW\source>perl faulk16.pl
string one is Sun
string two is 19
string three is 43
string four is 51
string five is -21
string six is 7.1
string seven is
Sun 19h 43m 51s -21 17.8' 0.984 -35.020 87.148 Set
...
Moon 10h 24m 21s +7 29.5' 58.6 ER -4.992 -102.785 Set
...
string one is Pluto
string two is 18
string three is 6
string four is 40
string five is -17
string six is 8.0
string seven is
Pluto 18h 6m 40s -17 44.9' 32.485 -52.833 108.052 Set
C:\MinGW\source>
^^^^^^^
I wonder why doesn't display.
--
larry gates
I suppose you could switch grammars once you've seen "use strict subs".
:-)
-- Larry Wall in <199804140117.SAA02006@wall.org>
------------------------------
Date: Wed, 21 Jan 2009 19:09:52 -0700
From: Larry Gates <larry@example.invalid>
Subject: Re: inputting the ephemerides
Message-Id: <1qppxjbf6q7be.gpzv1uketd3r$.dlg@40tude.net>
On Tue, 20 Jan 2009 15:43:55 +0000, RedGrittyBrick wrote:
> perldoc -f split
I couldn't get any input with split. I'm working up a data set that is
properly spaced and columnated.
>
> Assuming you don't mean
> perl -p -e 's/[^\s\d]//g' ephemerides.txt
What does this mean? I've been looking at regexs all day and am reminded
of days when I had to consume cyrillic data.
How would you get rid of the and the ' and leave the -44.6 in the
following:
-44.6'
?
--
larry gates
*** The previous line contains the naughty word "$&".\n
if /(ibm|apple|awk)/; # :-)
-- Larry Wall in the perl man page
------------------------------
Date: Wed, 21 Jan 2009 21:27:34 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: inputting the ephemerides
Message-Id: <slrngnfpt6.h41.tadmc@tadmc30.sbcglobal.net>
Larry Gates <larry@example.invalid> wrote:
> On Tue, 20 Jan 2009 15:43:55 +0000, RedGrittyBrick wrote:
>> Assuming you don't mean
>> perl -p -e 's/[^\s\d]//g' ephemerides.txt
>
> What does this mean?
What did you observe when you tried it?
It deletes all characters except for whitespace and digit characters.
perl -p -e 's/[^\s\d]+//g' ephemerides.txt
does the same thing, only faster.
I haven't benchmarked it, but I'd expect this to be faster still:
perl -p -e 'tr/ \n\r\t\f0123456789//dc' ephemerides.txt
> How would you get rid of the and the ' and leave the -44.6 in the
> following:
> -44.6'
s/[']//g;
or do it faster without using any regex at all:
tr/'//d; # tr/// does not use regular expressions
Perhaps you messed up the specification and are really looking for:
tr/' //d;
When _you_ look at the string, how do _you_ identify the part
that is "interesting"?
Once you can describe that well enough, then writing a pattern
that does it becomes easy or at least possible.
I'll assume that string is in $_.
Keep whatever looks like a number?
($num) = /(-?\d+\.?\d*)/;
(see: perldoc -q "scalar is a number")
Keep a number that comes after whitespace?
($num) = /\s(-?\d+\.?\d*)/;
Keep whatever non-whitespace comes before a "'"?
($num) = /(\S+)'/;
Keep whatever is between whitespace and "'"?
($num) = /\s(\S.*)'/;
or
($num) = /\s+(.+)'/;
Keep whatever comes after whitespace except the last character?
($num) = /\s+(.+)./;
And on and on and on...
You must first identify how the "interesting" part is distinguished
before you can devise a pattern that will match it.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Wed, 21 Jan 2009 19:59:59 -0800
From: Jrgen Exner <jurgenex@hotmail.com>
Subject: Re: inputting the ephemerides
Message-Id: <v3pfn4dska6grv3s8ah8sna3n18t060p7r@4ax.com>
Larry Gates <larry@example.invalid> wrote:
>How would you get rid of the and the ' and leave the -44.6 in the
>following:
> -44.6'
On way:
my $s = substr(' -44.6\'', 1, length($t)-2);
Another way
my @s = split(//,' -44.6\'');
my $s = join('', @s[1..$#s-1]);
Or you could play the old
chop
reverse
chop
reverse
trick.
I'm sure there are many more ways to remove the first and last character
of a string.
jue
------------------------------
Date: Wed, 21 Jan 2009 23:40:01 GMT
From: sln@netherlands.com
Subject: Re: Match CASE/END SQL Construct
Message-Id: <82cfn4d7chclr4ojic89tnsa142spkceib@4ax.com>
On Tue, 20 Jan 2009 20:08:02 GMT, sln@netherlands.com wrote:
>On Thu, 15 Jan 2009 15:05:29 -0500, "Perry Aynum" <jc_va@hotmail.com> wrote:
>
>>I am working on a SQL parser. I have a routine that recursively removes
>>enclosing parentheses and it works fine. Below is the regex that I use.
>>
>>However, I want to use the same routine, but instead of looking for
>>enclosing parens, I want to look for a string enclosed by CASE and END. Can
>>someone help me translate the regex below so that it will match a CASE/END
>>construct?
>>
>>Thanks very much.
>>
>>Parens
>>----------
>>(?:\s+)?\([^\(\)]*\)
>>
>>
>>
>>This is what I've managed so far with the CASE/END
>>
>>(?:\s+)?case(?!case|end)\s+end
>>
>
[snip explanation]
>use strict;
>use warnings;
>
>my $txt = join '', <DATA>;
>
>{
> my $cntr = 1;
>
> while ($txt =~ s/(?:\s+|^)case((?:.(?!\scase\s))*?)\s+end(\s+|$)/$1$2/is) # <- Production Regex, Ship to QA
> {
> print "\n<<<<<<<<<<< Phase".$cntr++." >>>>>>>>>>>\n";
> print "\$1= --------\n'$1'\n";
> print "\$txt= --------\n'$txt'\n";
> }
> print "\n\n************************\n FINAL:\n'$txt'\n";
>}
>
>__DATA__
>
>case
>1 case case end end
>2 case case end end
>fricases can erupt even among friends
>end
>
The regex needed a look-ahead for '\s', without it is's a bug.
///g was added to reduce passes, equals the depth of nesting now.
No more posts for a while. See ya later.
sln
-------------------------------------------------
use strict;
use warnings;
my $txt = join '', <DATA>;
my $cntr = 1;
while ($txt =~ s/(\s|^)case(?=\s)((?:(?!\scase\s).)*?\s)end(\s|$)/$1$2$3/isg)
{
print "\n<<<<<<<<<<< Phase".$cntr++." >>>>>>>>>>>\n";
print "\$txt= --------\n'$txt'\n";
}
print "\n\n************************\n FINAL:\n'$txt'\n";
__DATA__
case First Line
1 case line case end spacing end
2 case case end end
3 case case END end
fricases can erupt even among friends
end
case can erupt even among end
------------------------------
Date: Wed, 21 Jan 2009 15:46:59 -0800 (PST)
From: "C.DeRykus" <ced@blv-sam-01.ca.boeing.com>
Subject: Re: on Code references
Message-Id: <2bfec6a3-b112-4697-828a-dd39f19e4d33@o4g2000pra.googlegroups.com>
On Jan 21, 6:30 am, sharma...@hotmail.com wrote:
> On Jan 21, 6:22 pm, "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote:
>
>
>
> > sharma...@hotmail.com wrote in news:0a2d735d-066f-4f45-98b8-
> > 66fc1b957...@n33g2000pri.googlegroups.com:
>
> > > I am having trouble with calling subroutines using a reference
> > > variable.
>
> > > #!/usr/local/bin/perl
> > > use 5.8.0;
> > > use strict;
> > > use warnings;
>
> > > # anonymous subroutine stored in a reference variable
> > > my $reduce_ref = sub (&@) {
> > > my $code = shift;
> > > no strict 'refs';
>
> > > return shift unless @_ > 1;
>
> > > use vars qw($a $b);
>
> > > my $caller = caller;
> > > local(*{$caller."::a"}) = \my $a;
> > > local(*{$caller."::b"}) = \my $b;
>
> > > $a = shift;
> > > foreach (@_) {
> > > $b = $_;
> > > $a = &{$code}();
> > > }
>
> > > $a;
> > > };
>
> > > my @A = qw( 3 54 22);
>
> > > ## to compute the max of array
> > > print $reduce_ref->( { ($a > $b) ? $a : $b } @A);
> > > __END__
>
> > > ## this gives the following error:
> > > # Use of uninitialized value in numeric gt (>) at ...
> > > # Odd number of elements in anonymous hash at ...
> > > # Use of uninitialized value in anonymous hash ({}) at ...
> > > # Not a CODE reference at ...
>
> > Funny, it gives me:
>
> > C:\Temp> ttt
> > Array found where operator expected at C:\Temp\ttt.pl line 31, near "} "
> > (Missing operator before ?)
> > syntax error at C:\Temp\ttt.pl line 31, near "} @A" Execution of C:\Temp
> > \ttt.pl aborted due to compilation errors.
>
> > If I correct the last line:
>
> > print $reduce_ref->( sub { ($a > $b) ? $a : $b }, @A);
>
> > Then the script outputs 54.
>
> > The simple resolution of the problem aside, I am not sure why you want
> > to do this when you can use:
>
> >http://search.cpan.org/~gbarr/Scalar-List-Utils-1.19/lib/List/Util.pm
>
> > Sinan
> > --
> > A. Sinan Unur <1...@llenroc.ude.invalid>
> > (remove .invalid and reverse each component for email address)
>
> > comp.lang.perl.misc guidelines on the WWW:http://www.rehabitation.com/clpmisc/
>
> Thanks for resolving that!
>
> The error messages are differing maybe because of the OS differences.
> I ran on Sun-Solaris Unix.
>
> I am using the code from List::MoreUtils module, but was trying to use
> it
> as a code reference rather than a named subroutine.
s/List::MoreUtils/List::Util/
--
Charles DeRykus
------------------------------
Date: Thu, 22 Jan 2009 03:21:54 +0200
From: Eric Pozharski <whynot@pozharski.name>
Subject: Re: on Code references
Message-Id: <slrngnfik4.fk0.whynot@orphan.zombinet>
On 2009-01-21, A. Sinan Unur <1usa@llenroc.ude.invalid> wrote:
> sharma__r@hotmail.com wrote in news:0a2d735d-066f-4f45-98b8-
> 66fc1b95720f@n33g2000pri.googlegroups.com:
>
>> I am having trouble with calling subroutines using a reference
>> variable.
Actually, you have reading trouble. You're supposed to copy-paste your
code and *anyway* provide *exact* error messages. Maybe you'll just go
back to killfile where you've came from?
*SKIP*
> Funny, it gives me:
>
> C:\Temp> ttt
> Array found where operator expected at C:\Temp\ttt.pl line 31, near "} "
> (Missing operator before ?)
> syntax error at C:\Temp\ttt.pl line 31, near "} @A" Execution of C:\Temp
> \ttt.pl aborted due to compilation errors.
>
Forget him. Look what I've found.
{62446:61} [0:0]$ perl -MO=Deparse -wle ' { $x ? $y : $z } @A '
Useless use of a variable in void context at -e line 1.
Useless use of a variable in void context at -e line 1.
Useless use of a variable in void context at -e line 1.
Name "main::y" used only once: possible typo at -e line 1.
Name "main::z" used only once: possible typo at -e line 1.
Name "main::x" used only once: possible typo at -e line 1.
Name "main::A" used only once: possible typo at -e line 1.
BEGIN { $^W = 1; }
BEGIN { $/ = "\n"; $\ = "\n"; }
{
$x ? $y : $z;
}
@A;
-e syntax OK
If I swap block(?) and array, then it becomes hash slice. But what is
this?
*CUT*
--
Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom
------------------------------
Date: Thu, 22 Jan 2009 01:24:18 +0100
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: What do you need to have to be considered a Master at Perl?
Message-Id: <4977bcb2$0$186$e4fe514c@news.xs4all.nl>
Tad J McClellan wrote:
> I think my solution will allow plenty damnfoolery and still
> yield a usable US telephone number:
>
> sub validate_phonenumber {
> my($phone) = @_;
>
> $phone =~ s/\D+//g; # allow hyphens, dots, parens, spaces etc
s/allow/remove/
Another test question: How many elements does the \d character set have?
s/\\D/[^0-9]/
--
Ruud
------------------------------
Date: Tue, 20 Jan 2009 23:36:45 -0800
From: Xho Jingleheimerschmidt <xhoster@gmail.com>
Subject: Re: What do you need to have to be considered a Master at Perl?
Message-Id: <4977c82d$0$6446$ed362ca5@nr5c.newsreader.com>
Charlton Wilbur wrote:
> One of my favorites:
>
> You have a string that comes from a freeform text field where the user
> is expected to enter a telephone number. Write a regular expression to
> validate it and capture a usable phone number.
Usable by whom? If by some kind of computerized system, then I'd need
to know more about that system it is going into. If the number is to be
regurgitated to a human for the human to use, I'd by inclined to not
validate at all, present it to the human as is and let the human do
whatever validation/interpretation may be needed.
And, am I allowed to make long distance calls? International? Call the
Waltons on Walton's Mountain?
> This is usually good for a lot of discussion about what should be valid,
> and about the damnfool things that users do. It also shows whether the
> candidate has a grasp of basic regular expressions: programmers who are
> comfortable with them usually try to figure out what foolish things a
> user is likely to do, while programmers who are not comfortable with
> them usually try to remember what the syntax is for capturing.
>
> Charlton
Xho
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 2147
***************************************