[28991] in Perl-Users-Digest
Perl-Users Digest, Issue: 235 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Mar 17 21:09:53 2007
Date: Sat, 17 Mar 2007 18:09:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 17 Mar 2007 Volume: 11 Number: 235
Today's topics:
Re: Login time quota <cdalten@gmail.com>
Re: Login time quota <koos@geen.spam>
Re: Mastering Perl <brian.d.foy@gmail.com>
Module for random array distribution <balrog2000@o2.pl>
Re: Module for random array distribution xhoster@gmail.com
Reading STDIN seems to be breaking my script <ramon@conexus.net>
Re: Reading STDIN seems to be breaking my script <ramon@conexus.net>
Re: Reading STDIN seems to be breaking my script anno4000@radom.zrz.tu-berlin.de
Re: Reading STDIN seems to be breaking my script <ramon@conexus.net>
Re: Reading STDIN seems to be breaking my script <hjp-usenet2@hjp.at>
Re: Reading STDIN seems to be breaking my script anno4000@radom.zrz.tu-berlin.de
Re: Reading STDIN seems to be breaking my script <joe@inwap.com>
Re: Reading STDIN seems to be breaking my script <abigail@abigail.be>
Re: Reading STDIN seems to be breaking my script <tadmc@augustmail.com>
regex for lines not containing |, not working <jbl02NO@SPAMhotmail.com>
Re: regex for lines not containing |, not working (Alan Curry)
Re: regex for lines not containing |, not working <wahab-mail@gmx.de>
Re: regex for lines not containing |, not working <bik.mido@tiscalinet.it>
Re: regex for lines not containing |, not working <tadmc@augustmail.com>
Re: Scope and Arrays anno4000@radom.zrz.tu-berlin.de
Screen Scrapping <colleen1980@gmail.com>
Re: Screen Scrapping <wahab-mail@gmx.de>
Re: Screen Scrapping <tadmc@augustmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 17 Mar 2007 08:40:34 -0700
From: "grocery_stocker" <cdalten@gmail.com>
Subject: Re: Login time quota
Message-Id: <1174146034.088669.148710@e65g2000hsc.googlegroups.com>
On Mar 17, 8:07 am, Koos Pol <k...@geen.spam> wrote:
> After unfruitful debates with my teenage daughter about not spending too
> much time on her computer, I decided to take the more eh, pragmatic
> approach. As I couldn't find any program that suites me, I've written a
> small Perl script that you can launch from your Un*x boot scripts.
> You can run it like
>
> login_quota -u mary -t 120 &
>
> This will make sure Mary does not spend more that her alloted 120 minutes.
>
> Some things perhaps noteworthy:
> - It pauses timing when Mary's screensaver is running
> - It can be fooled if she leaves a screensaver running on another X display
> - Configuration locations are hard coded.
> - It could use a day scheme variation. It would be nice to allow different
> quota for for instance weekends.
>
> But as it suits me already I'm not bothering to take it up another step.
> If anyone wants to steal or borrow it, please feel free. I would appreciate
> it though if you make your improvements public.
Isn't this a bit excessive? Wouldn't have just been easier to either
install something like logoutd or configure PAM to limit her login
time? Maybe I need to take a closer look at the script, but what
happens say if she is on two hours and the script kicks over and then
she decides to reboot the machine? Will the script remember this? Sir,
I think you underestimate the power of a bored teenager.
------------------------------
Date: Sat, 17 Mar 2007 19:17:36 +0100
From: Koos Pol <koos@geen.spam>
Subject: Re: Login time quota
Message-Id: <45fc30c0$0$323$e4fe514c@news.xs4all.nl>
On zaterdag 17 maart 2007 16:40 grocery_stocker wrote:
> Isn't this a bit excessive? Wouldn't have just been easier to either
> install something like logoutd
Too bad I haven't heard of that one when I initially was searching for
someting suitable.
> or configure PAM to limit her login
> time?
I never got to understand PAM really.
> Maybe I need to take a closer look at the script, but what
> happens say if she is on two hours and the script kicks over and then
> she decides to reboot the machine? Will the script remember this?
Yes. It writes to a personal timer file.
> Sir,
> I think you underestimate the power of a bored teenager.
I know. I have one :-)
Koos
--
43rd Law of Computing: Anything that can go wr
fortune: Segmentation violation -- Core dumped
------------------------------
Date: Sat, 17 Mar 2007 11:12:43 -0700
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: Mastering Perl
Message-Id: <170320071112438745%brian.d.foy@gmail.com>
In article <slrnevlele.tif.justin.0703@stigmata.purestblue.com>, Justin
C <justin.0703@purestblue.com> wrote:
> On 2007-03-16, Michele Dondi <bik.mido@tiscalinet.it> wrote:
> > On 16 Mar 2007 00:15:30 -0700, "The Count" <gerald607@gmail.com>
> > wrote:
> >>Im a BSc4 Maths/Computer Science student and would like to find out
> >>the best way to learn programming in perl.
The best way depends on how you like to learn.
> >>.How long could it take me to master perl to a
> >>level where I can make web applications?
I'm still trying to master Perl :)
> > In any case start with an introdutory
> > book, like the Llama.
>
> [snip]
>
> I'll second the Llama. It's my most thumbed book. I know where
> everything is in there and, for those moments when I can't remember the
> correct syntax (quite often then), it's invaluable.
Besides the Llama (which is _Learning Perl_, in case someone forgot to
mention that), there is _Intermediate Perl_ (the Alpaca), and soon
there will be _Mastering Perl_. We designed those books as a
progression from beginner to advanced programmer. _Mastering Perl_
is currently in production for a summer release, but also online:
http://www.pair.com/comdog/mastering_perl
I also have a _Learning Perl Study Guide_, a companion to _Learning
Perl_ with additional exercises and answers:
http://www.theperlreview.com/learning_perl_study_guide/
You might be interested in other books, and most of the Perl ones are
on:
http://books.perl.org
--
Posted via a free Usenet account from http://www.teranews.com
------------------------------
Date: Sun, 18 Mar 2007 01:11:33 +0100
From: Tomek <balrog2000@o2.pl>
Subject: Module for random array distribution
Message-Id: <op.tpcytjg8bdw0a5@balrog2>
Hello!
First of all, it is very hard to search CPAN for that module, cause almost
all modules contain words array and distribution ;)
What am I going to achieve is to semi-randomly fill an array. There are 2
main goals: sum of elements, and min/max for each elem)
I have for example 2000 to split between 100 array elements. I don't want
to do this equally ( 100 x 20 ), but want to set a deviation, for example
50% so that minimum value for element is 5 and maximum is 15. All that
have to sum up to 2000 at the end.
I am sure somebody already written such module, I just can find it :(
Regards, T. Kraus
------------------------------
Date: 18 Mar 2007 00:28:58 GMT
From: xhoster@gmail.com
Subject: Re: Module for random array distribution
Message-Id: <20070317202902.045$I9@newsreader.com>
Tomek <balrog2000@o2.pl> wrote:
> Hello!
>
> First of all, it is very hard to search CPAN for that module, cause
> almost all modules contain words array and distribution ;)
The word "array" is not going to be particularly useful, anyway. Most
modules are going to be named by what they do, not by what data structure
they will use to store the results of what they do.
>
> What am I going to achieve is to semi-randomly fill an array. There are 2
> main goals: sum of elements, and min/max for each elem)
>
> I have for example 2000 to split between 100 array elements. I don't want
> to do this equally ( 100 x 20 ), but want to set a deviation, for example
> 50% so that minimum value for element is 5 and maximum is 15. All that
> have to sum up to 2000 at the end.
That isn't unambiguously described. How do you get the 5 and 15 out of
50%? What distribution must the numbers approximately follow (uniform,
gaussian, exponential, don't care)? Do the min and max and the sum need to
be achieved precisely or only asymptomatically?
> I am sure somebody already written such module, I just can find it :(
I don't see why this would be particularly likely to have had a module
written for it. It seems like a pretty unusual request, at least as
stated.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 17 Mar 2007 10:00:38 -0700
From: "Ramon F Herrera" <ramon@conexus.net>
Subject: Reading STDIN seems to be breaking my script
Message-Id: <1174150838.060106.67060@o5g2000hsb.googlegroups.com>
Anyone familiar with the Asterisk open source PBX out there? Read
on...
An AGI (Asterisk Gateway Interface) Perl script is very similar to a
CGI Perl script. My problem is introduced by the code commented out
below. As soon as the code is executed, the rest of the script doesn't
work anymore because the prompt is either not payed or (most likely)
it is played nut I cannot hear it.
-Ramon
---------------------
#!/bin/perl -w
use Asterisk::AGI;
$|=1;
my $AGI = new Asterisk::AGI;
my %input = $AGI->ReadParse();
sleep(1);
# while(<STDIN>) {
# chomp;
# last unless length($_);
# if (/^agi_(\w+)\:\s+(.*)$/) {
# $AGI{$1} = $2;
# }
# }
#
# $CallerID = $AGI{"agi_callerid"};
# $CallerIdName = $AGI{"agi_calleridname"};
$Welcome = "faxback/Welcome";
$enterFaxNumber = "faxback/EnterFaxNumber";
$Farewell = "faxback/Farewell";
$AGI->stream_file("$Welcome", "*");
$FaxNumber = $AGI->get_data($enterFaxNumber, "10000", "11");
------------------------------
Date: 17 Mar 2007 10:27:09 -0700
From: "Ramon F Herrera" <ramon@conexus.net>
Subject: Re: Reading STDIN seems to be breaking my script
Message-Id: <1174152429.230121.43370@e65g2000hsc.googlegroups.com>
Anyone familiar with the Asterisk open source PBX out there? Read
on...
An AGI (Asterisk Gateway Interface) Perl script is very similar to a
CGI Perl script. My problem is introduced by the code commented out
below. As soon as the code is executed, the rest of the script doesn't
work anymore because the prompt is either not played or (most likely)
it is played but I cannot hear it.
-Ramon
---------------------
#!/bin/perl -w
use Asterisk::AGI;
$|=1;
my $AGI = new Asterisk::AGI;
my %input = $AGI->ReadParse();
sleep(1);
# while(<STDIN>) {
# chomp;
# last unless length($_);
# if (/^agi_(\w+)\:\s+(.*)$/) {
# $AGI{$1} = $2;
# }
# }
#
# $CallerID = $AGI{"agi_callerid"};
# $CallerIdName = $AGI{"agi_calleridname"};
$Welcome = "faxback/Welcome";
$enterFaxNumber = "faxback/EnterFaxNumber";
$Farewell = "faxback/Farewell";
$AGI->stream_file("$Welcome", "*");
$FaxNumber = $AGI->get_data($enterFaxNumber, "10000", "11");
[...]
------------------------------
Date: 17 Mar 2007 18:00:11 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Reading STDIN seems to be breaking my script
Message-Id: <562olbF27ev2tU1@mid.dfncis.de>
Ramon F Herrera <ramon@conexus.net> wrote in comp.lang.perl.misc:
>
> Anyone familiar with the Asterisk open source PBX out there? Read
> on...
>
> An AGI (Asterisk Gateway Interface) Perl script is very similar to a
> CGI Perl script. My problem is introduced by the code commented out
> below. As soon as the code is executed, the rest of the script doesn't
> work anymore because the prompt is either not played or (most likely)
> it is played but I cannot hear it.
> -Ramon
>
> ---------------------
> #!/bin/perl -w
>
> use Asterisk::AGI;
>
> $|=1;
> my $AGI = new Asterisk::AGI;
> my %input = $AGI->ReadParse();
> sleep(1);
>
> # while(<STDIN>) {
> # chomp;
> # last unless length($_);
> # if (/^agi_(\w+)\:\s+(.*)$/) {
> # $AGI{$1} = $2;
This line accesses the hash %main::AGI. It seems unlikely that
you want to do this. It wouldn't run under strict.
> # }
> # }
> #
> # $CallerID = $AGI{"agi_callerid"};
> # $CallerIdName = $AGI{"agi_calleridname"};
>
> $Welcome = "faxback/Welcome";
> $enterFaxNumber = "faxback/EnterFaxNumber";
> $Farewell = "faxback/Farewell";
>
> $AGI->stream_file("$Welcome", "*");
>
> $FaxNumber = $AGI->get_data($enterFaxNumber, "10000", "11");
>
> [...]
The commented-out code would very probably not work as intended
anyhow. Make sure it does what you want it to do. As a first
step, add "use strict;" near the beginning of the script.
Anno
------------------------------
Date: 17 Mar 2007 11:14:14 -0700
From: "Ramon F Herrera" <ramon@conexus.net>
Subject: Re: Reading STDIN seems to be breaking my script
Message-Id: <1174155254.655504.217390@o5g2000hsb.googlegroups.com>
On Mar 17, 1:00 pm, anno4...@radom.zrz.tu-berlin.de wrote:
> Ramon F Herrera <r...@conexus.net> wrote in comp.lang.perl.misc:
>
>
>
>
>
> > Anyone familiar with the Asterisk open source PBX out there? Read
> > on...
>
> > An AGI (Asterisk Gateway Interface) Perl script is very similar to a
> > CGI Perl script. My problem is introduced by the code commented out
> > below. As soon as the code is executed, the rest of the script doesn't
> > work anymore because the prompt is either not played or (most likely)
> > it is played but I cannot hear it.
> > -Ramon
>
> > ---------------------
> > #!/bin/perl -w
>
> > use Asterisk::AGI;
>
> > $|=1;
> > my $AGI = new Asterisk::AGI;
> > my %input = $AGI->ReadParse();
> > sleep(1);
>
> > # while(<STDIN>) {
> > # chomp;
> > # last unless length($_);
> > # if (/^agi_(\w+)\:\s+(.*)$/) {
> > # $AGI{$1} = $2;
>
> This line accesses the hash %main::AGI. It seems unlikely that
> you want to do this. It wouldn't run under strict.
>
> > # }
> > # }
> > #
> > # $CallerID = $AGI{"agi_callerid"};
> > # $CallerIdName = $AGI{"agi_calleridname"};
>
> > $Welcome = "faxback/Welcome";
> > $enterFaxNumber = "faxback/EnterFaxNumber";
> > $Farewell = "faxback/Farewell";
>
> > $AGI->stream_file("$Welcome", "*");
>
> > $FaxNumber = $AGI->get_data($enterFaxNumber, "10000", "11");
>
> > [...]
>
> The commented-out code would very probably not work as intended
> anyhow. Make sure it does what you want it to do. As a first
> step, add "use strict;" near the beginning of the script.
>
> Anno
Thanks for your help, Anno. I took the commented out code from an AGI
program called agi-test.agi which works and comes with the Asterisk
distribution. However, I did neglect to place the "use strict" line,
and after I added it I am getting all kinds of errors like this one:
Global symbol "$Welcome" requires explicit package name at
faxback.agi line 24.
I guess my problem is that when I learned Perl, there was no such
thing as "my". What the heck is that? I have a vague recollection that
it was added to make the language object oriented? Where can I read
about that stuff? Is there a guide about this "my" new deal for
programmers who already know the "old" Perl?
TIA,
-Ramon
------------------------------
Date: Sat, 17 Mar 2007 19:38:24 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Reading STDIN seems to be breaking my script
Message-Id: <slrnevodd0.6bb.hjp-usenet2@yoyo.hjp.at>
On 2007-03-17 18:14, Ramon F Herrera <ramon@conexus.net> wrote:
> I guess my problem is that when I learned Perl, there was no such
> thing as "my".
Must have been a long time ago. if I remember correctly, "my" was
introduced with perl 5.0 in 1994.
> What the heck is that? I have a vague recollection that
> it was added to make the language object oriented?
No, it just declares a lexically scoped local variable, as most other
programming languages have them (unlike "local" which creates a
dynamically scoped local variable).
> Where can I read about that stuff? Is there a guide about this "my"
> new deal for programmers who already know the "old" Perl?
perldoc is your friend.
perldoc -f my
gives you a short description and also says 'See "Private Variables via
my()" in perlsub for details'. So
perldoc perlsub
is what you should read. If you ares still used to perl4, you should
probably read all of the other core docs as well.
hp
--
_ | Peter J. Holzer | Blaming Perl for the inability of programmers
|_|_) | Sysadmin WSR | to write clearly is like blaming English for
| | | hjp@hjp.at | the circumlocutions of bureaucrats.
__/ | http://www.hjp.at/ | -- Charlton Wilbur in clpm
------------------------------
Date: 17 Mar 2007 19:32:33 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Reading STDIN seems to be breaking my script
Message-Id: <562u2hF277i3sU1@mid.dfncis.de>
Ramon F Herrera <ramon@conexus.net> wrote in comp.lang.perl.misc:
> On Mar 17, 1:00 pm, anno4...@radom.zrz.tu-berlin.de wrote:
> > Ramon F Herrera <r...@conexus.net> wrote in comp.lang.perl.misc:
> >
> >
> >
> >
> >
> > > Anyone familiar with the Asterisk open source PBX out there? Read
> > > on...
[snip, mostly code]
> > The commented-out code would very probably not work as intended
> > anyhow. Make sure it does what you want it to do. As a first
> > step, add "use strict;" near the beginning of the script.
> >
> > Anno
>
>
> Thanks for your help, Anno. I took the commented out code from an AGI
> program called agi-test.agi which works and comes with the Asterisk
> distribution. However, I did neglect to place the "use strict" line,
> and after I added it I am getting all kinds of errors like this one:
>
> Global symbol "$Welcome" requires explicit package name at
> faxback.agi line 24.
>
> I guess my problem is that when I learned Perl, there was no such
> thing as "my". What the heck is that? I have a vague recollection that
> it was added to make the language object oriented? Where can I read
> about that stuff? Is there a guide about this "my" new deal for
> programmers who already know the "old" Perl?
Well, the new deal is Perl 5 and happened twelve years ago.
If you are going to pick up Perl (again), you should definitely learn
about "my()" (lexical variables, nothing to do with OO) and more things
that were added with Perl 5. "perldoc -f my" is the documentation of
"my()", but there's much more.
If the code you're dealing with is not strict-safe, I'd eye it with
suspicion.
If it *is* strict-safe, and you have taken a snippet of (modern) Perl
and are trying to make it run under Perl 4 style code you wrote, forget
it. Start with the whole thing and modify it to do what you want it
to do, sticking to the style you find, learning about (looking up) new
features as you go along.
Anno
------------------------------
Date: Sat, 17 Mar 2007 15:27:25 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: Reading STDIN seems to be breaking my script
Message-Id: <J6CdnW7l9KXJ9mHYnZ2dnUVZ_oernZ2d@comcast.com>
Ramon F Herrera wrote:
> On Mar 17, 1:00 pm, anno4...@radom.zrz.tu-berlin.de wrote:
>
> I guess my problem is that when I learned Perl, there was no such
> thing as "my". What the heck is that? I have a vague recollection that
> it was added to make the language object oriented? Where can I read
> about that stuff?
For starters, use the command "perldoc perl" (or "man perl").
It has a list of topics that make up Perl's core documentation set.
In particular, you should look at this section in "perldoc perltrap":
Perl4 to Perl5 Traps
Practicing Perl4 Programmers should take note of the following
Perl4-to-Perl5 specific traps.
They're crudely ordered according to the following list:
Discontinuance, Deprecation, and BugFix traps
Anything that's been fixed as a perl4 bug, removed as a perl4 fea-
ture or deprecated as a perl4 feature with the intent to encourage
usage of some other perl5 feature.
Parsing Traps
Traps that appear to stem from the new parser.
Numerical Traps
Traps having to do with numerical or mathematical operators.
General data type traps
Traps involving perl standard data types.
Context Traps - scalar, list contexts
Traps related to context within lists, scalar statements/declara-
tions.
Precedence Traps
Traps related to the precedence of parsing, evaluation, and execu-
tion of code.
General Regular Expression Traps using s///, etc.
Traps related to the use of pattern matching.
Subroutine, Signal, Sorting Traps
Traps related to the use of signals and signal handlers, general
subroutines, and sorting, along with sorting subroutines.
OS Traps
OS-specific traps.
DBM Traps
Traps specific to the use of "dbmopen()", and specific dbm imple-
mentations.
Unclassified Traps
Everything else.
If you find an example of a conversion trap that is not listed here,
please submit it to <perlbug@perl.org> for inclusion. Also note that
at least some of these can be caught with the "use warnings" pragma or
the -w switch.
------------------------------
Date: 17 Mar 2007 23:23:52 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: Reading STDIN seems to be breaking my script
Message-Id: <slrnevou3g.ech.abigail@alexandra.abigail.be>
Ramon F Herrera (ramon@conexus.net) wrote on MMMMCMXLVI September
MCMXCIII in <URL:news:1174155254.655504.217390@o5g2000hsb.googlegroups.com>:
~~ On Mar 17, 1:00 pm, anno4...@radom.zrz.tu-berlin.de wrote:
~~ > Ramon F Herrera <r...@conexus.net> wrote in comp.lang.perl.misc:
~~ >
~~ >
~~ >
~~ >
~~ >
~~ > > Anyone familiar with the Asterisk open source PBX out there? Read
~~ > > on...
~~ >
~~ > > An AGI (Asterisk Gateway Interface) Perl script is very similar to a
~~ > > CGI Perl script. My problem is introduced by the code commented out
~~ > > below. As soon as the code is executed, the rest of the script doesn't
~~ > > work anymore because the prompt is either not played or (most likely)
~~ > > it is played but I cannot hear it.
~~ > > -Ramon
~~ >
~~ > > ---------------------
~~ > > #!/bin/perl -w
~~ >
~~ > > use Asterisk::AGI;
~~ >
~~ > > $|=1;
~~ > > my $AGI = new Asterisk::AGI;
~~ > > my %input = $AGI->ReadParse();
~~ > > sleep(1);
~~ >
~~ > > # while(<STDIN>) {
~~ > > # chomp;
~~ > > # last unless length($_);
~~ > > # if (/^agi_(\w+)\:\s+(.*)$/) {
~~ > > # $AGI{$1} = $2;
~~ >
~~ > This line accesses the hash %main::AGI. It seems unlikely that
~~ > you want to do this. It wouldn't run under strict.
~~ >
~~ > > # }
~~ > > # }
~~ > > #
~~ > > # $CallerID = $AGI{"agi_callerid"};
~~ > > # $CallerIdName = $AGI{"agi_calleridname"};
~~ >
~~ > > $Welcome = "faxback/Welcome";
~~ > > $enterFaxNumber = "faxback/EnterFaxNumber";
~~ > > $Farewell = "faxback/Farewell";
~~ >
~~ > > $AGI->stream_file("$Welcome", "*");
~~ >
~~ > > $FaxNumber = $AGI->get_data($enterFaxNumber, "10000", "11");
~~ >
~~ > > [...]
~~ >
~~ > The commented-out code would very probably not work as intended
~~ > anyhow. Make sure it does what you want it to do. As a first
~~ > step, add "use strict;" near the beginning of the script.
~~ >
~~ > Anno
~~
~~
~~ Thanks for your help, Anno. I took the commented out code from an AGI
~~ program called agi-test.agi which works and comes with the Asterisk
~~ distribution. However, I did neglect to place the "use strict" line,
~~ and after I added it I am getting all kinds of errors like this one:
~~
~~ Global symbol "$Welcome" requires explicit package name at
~~ faxback.agi line 24.
~~
~~ I guess my problem is that when I learned Perl, there was no such
~~ thing as "my". What the heck is that? I have a vague recollection that
~~ it was added to make the language object oriented? Where can I read
~~ about that stuff? Is there a guide about this "my" new deal for
~~ programmers who already know the "old" Perl?
'my' was introduced in Perl 5.000, which dates from 1994. The same
version introduced 'strict.pm', a module that you must use to get the
'Global symbol "$Welcome" requires explicit package name' error message.
Not to mention that objects were introduced in 5.000 as well.
I'm a bit baffled that you claim to be ignorant of Perl5 features, yet
you do use them.
Note that Perl doesn't require to use 'my'.
Abigail
--
sub _ {$_ = shift and y/b-yB-Y/a-yB-Y/ xor !@ _?
exit print :
print and push @_ => shift and goto &{(caller (0)) [3]}}
split // => "KsvQtbuf fbsodpmu\ni flsI " xor & _
------------------------------
Date: Sat, 17 Mar 2007 19:54:40 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Reading STDIN seems to be breaking my script
Message-Id: <slrnevp3eg.h7d.tadmc@tadmc30.august.net>
Ramon F Herrera <ramon@conexus.net> wrote:
> I guess my problem is that when I learned Perl, there was no such
> thing as "my".
> Where can I read
> about that stuff?
"Coping with Scoping":
http://perl.plover.com/FAQs/Namespaces.html
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 17 Mar 2007 14:54:08 -0500
From: jbl <jbl02NO@SPAMhotmail.com>
Subject: regex for lines not containing |, not working
Message-Id: <9jgov2pv99e9jsdrjjc0h3fup2q59tiphv@4ax.com>
I have two problems.
(1) I get the warning, Use of uninitialized value in pattern match
(m//) at xxx.pl line 12, <DATA> line 9., when warnings are enableed.
This runs with warnings disabeled but the regex is not working
correctly.
(2) In the sample data, some lines contain a pipe symbol |, and some
do not. I only want to print the 3 lines without the pipe symbol, |
thanks,
jbl
#!/usr/bin/perl
#use warnings;
use strict;
my (@lines);
while (<DATA>)
{
push @lines, $_;
}
foreach my $line (@lines)
{
# if pipe symbol not present in line, print the line
if ( /^((?!\|).)*$/ ) {
print $line;
}
}
__DATA__
0:00:03 DEBILITATING EFFECTS O
0:00:03 DEBILITATING EFFECTS ON
0:00:03 DEBILITATING EFFECTS ON|FA
0:00:03 DEBILITATING EFFECTS ON|FAMIL
0:00:03 DEBILITATING EFFECTS ON|FAMILIES
0:00:04 FAMILIES, SOCIAL STRUCTURES.
0:00:05 FAMILIES, SOCIAL STRUCTURES.|IT
0:00:05 FAMILIES, SOCIAL STRUCTURES.|IT W
0:00:05 FAMILIES, SOCIAL STRUCTURES.|IT WIL
------------------------------
Date: Sat, 17 Mar 2007 20:09:36 +0000 (UTC)
From: pacman@TheWorld.com (Alan Curry)
Subject: Re: regex for lines not containing |, not working
Message-Id: <ethhu0$ci$1@pcls4.std.com>
In article <9jgov2pv99e9jsdrjjc0h3fup2q59tiphv@4ax.com>,
jbl <jbl02NO@SPAMhotmail.com> wrote:
>I have two problems.
They are related. When you fix the first one, the second one will be gone.
>(1) I get the warning, Use of uninitialized value in pattern match
>(m//) at xxx.pl line 12, <DATA> line 9., when warnings are enableed.
>
>This runs with warnings disabeled but the regex is not working
>correctly.
It's working, but you're comparing it against the wrong string! You used a
/match/ operator without =~ so you're testing $_ which is the uninitialized
value.
>foreach my $line (@lines)
>{
> # if pipe symbol not present in line, print the line
> if ( /^((?!\|).)*$/ ) {
You meant to say
if( $line =~ /^((?!\|).)*$/ )
Which could be more concisely written as
if ( $line =~ /^[^|]*$/ )
or even
if ( $line !~ /\|/ )
There's no need for negative lookahead to do a test this simple. (It is sort
of impressive that you put together a correctly functioning regular
expression involving negative lookahead within a repeated group though.)
--
Alan Curry
pacman@world.std.com
------------------------------
Date: Sat, 17 Mar 2007 21:29:30 +0100
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: regex for lines not containing |, not working
Message-Id: <ethjd3$365$1@mlucom4.urz.uni-halle.de>
jbl wrote:
> #!/usr/bin/perl
> #use warnings;
> use strict;
> my (@lines);
> while (<DATA>)
> {
> push @lines, $_;
> }
> foreach my $line (@lines)
> {
> # if pipe symbol not present in line, print the line
> if ( /^((?!\|).)*$/ ) {
> print $line;
> }
> }
Your whole program reduces to
print grep !/\|/, <DATA>;
Which means (right to left):
- read from _DATA_ in list context (all lines)
- check each line by grep and let it pass
if !(not) \| is present (must be escaped)
- print the 'passed through' list
Regards
Mirco
------------------------------
Date: Sat, 17 Mar 2007 21:54:38 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: regex for lines not containing |, not working
Message-Id: <v3lov25ooouq81ajcoeupevnjagpe79s19@4ax.com>
On Sat, 17 Mar 2007 14:54:08 -0500, jbl <jbl02NO@SPAMhotmail.com>
wrote:
>while (<DATA>)
>{
> push @lines, $_;
>}
>foreach my $line (@lines)
That's just a very inefficient way to slurp the whole file in @lines.
More efficient would be
my @lines=<DATA>;
foreach my $line (@lines) { # ...
In which case you don't really need @lines:
foreach my $line (<DATA>) { # ...
But that would still be slurping which is bad(TM), because
unnecessary:
while (my $line=<DATA>) { # ...
> # if pipe symbol not present in line, print the line
> if ( /^((?!\|).)*$/ ) {
> print $line;
print $line if $line !~ /\|/;
But then I would avoid using a lexical $line altogether:
/\|/ or print while <DATA>;
HTH,
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Sat, 17 Mar 2007 19:57:42 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: regex for lines not containing |, not working
Message-Id: <slrnevp3k6.h7d.tadmc@tadmc30.august.net>
jbl <jbl02NO@SPAMhotmail.com> wrote:
> This runs with warnings disabeled
Then it will also run with warnings enabled.
warnings do not affect the execution of your program, they just spit
out some extra stuff on STDERR.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 17 Mar 2007 16:48:33 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Scope and Arrays
Message-Id: <562kf1F274249U1@mid.dfncis.de>
Brian McCauley <nobull67@gmail.com> wrote in comp.lang.perl.misc:
> On Mar 16, 4:40 pm, "Peter J. Holzer" <hjp-usen...@hjp.at> wrote:
>
> > So one (rather ugly, I admit) solution would be to
> > change "my $message;" into "our $message;":
> >
> > our $message;
> > my @messages = ("Hello", "Goodbye");
> >
> > foreach $message (@messages) {
> > displayPrint();
> > }
> >
> > sub displayPrint {
> >
> > print "My message is $message.\n";
> >
> > }
> >
> > prints
> >
> > My message is Hello.
> > My message is Goodbye.
> >
> > I like Anno's way with the hash better, though (that's how I
> > would do it).
>
> I think that the global variables design pattern should not be
> dismissed out of hand. If used widely they will make code
> unmaintainable and unreadable. But used sparingly they can make for
> more readable and more maintainable.
>
> To see my epiphany:
>
> http://groups.google.com/group/comp.lang.perl.misc/browse_frm/thread/e00e827ea3f9ab6f/2fbfe18a8d5e7acd#2fbfe18a8d5e7acd
I haven't followed your example in detail but I've seen similar cases.
I think it's no coincidence that your problem was recursive. Some
recursive knots can be solved by introduction of a global variable or
two. The sword of globality, as it were.
However, the code the OP has to deal with seems to be based on the
Design Pattern of "Make Everything Global and Access at Will". (MEGAW?)
That only works for small, one-off scripts. The problem is that small
one-off scripts get re-used and extended in infinitesimal steps way
beyond the breaking point.
Anno
------------------------------
Date: 17 Mar 2007 16:28:40 -0700
From: "Anna" <colleen1980@gmail.com>
Subject: Screen Scrapping
Message-Id: <1174174120.892744.197940@o5g2000hsb.googlegroups.com>
Hi: This is the site which gives information about social security
Death index search. Is there any way i can pass the social number
directly thru Perl program in the web site and get the three records
Name, Birth, Death in my computer. I heard some thing about screen
scrapping but no idea how to i use it
http://ssdi.rootsweb.com/
Thanks.
------------------------------
Date: Sun, 18 Mar 2007 00:46:22 +0100
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: Screen Scrapping
Message-Id: <eti1h1$7i5$1@mlucom4.urz.uni-halle.de>
Anna wrote:
> Hi: This is the site which gives information about social security
> Death index search. Is there any way i can pass the social number
> directly thru Perl program in the web site and get the three records
> Name, Birth, Death in my computer. I heard some thing about screen
> scrapping but no idea how to i use it
> http://ssdi.rootsweb.com/
This sound like a question for
a programmers job assignement.
Added: "you have ten minutes from now" ;-)
You could simply pull the stuff by LWP::UserAgent
and parse the resulting HTML response, like
(quick & dirty):
use strict;
use warnings;
use LWP::UserAgent;
my %lookup = (
firstname => 'George', middlename => 'W', lastname => 'Bush',
ssn =>'', nt => 'exact', stat => ''
);
my $url = 'ssdi.rootsweb.com/cgi-bin/ssdi.cgi';
my $rgx = qr{^<tr><td>(.*?)</td><td>(.*?)</td><td>(.*?)</td><td>(.*?)</td></tr>$};
my $uag = LWP::UserAgent->new( agent=>'MSIE/6.0' );
my @txt = map { /$rgx/ ? [$1, $2, $3] : () } split /\n/,
$uag->post('http://'.$url, \%lookup)->as_string;
# stuff is now in $_->[0], $_->[1],$_->[2],
print "@$_\n", for @txt;
Just enter the search term in %lookup and
parse the response fields.
Regards
Mirco
------------------------------
Date: Sat, 17 Mar 2007 20:03:12 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Screen Scrapping
Message-Id: <slrnevp3ug.h7d.tadmc@tadmc30.august.net>
Anna <colleen1980@gmail.com> wrote:
> Hi: This is the site which gives information about social security
> Death index search. Is there any way i can pass the social number
> directly thru Perl program in the web site and get the three records
> Name, Birth, Death in my computer. I heard some thing about screen
> scrapping but no idea how to i use it
> http://ssdi.rootsweb.com/
Start with the FAQ answer to your question:
How do I automate an HTML form submission?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
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 235
**************************************