[22104] in Perl-Users-Digest
Perl-Users Digest, Issue: 4326 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Dec 31 21:15:55 2002
Date: Tue, 31 Dec 2002 18:15:27 -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 Tue, 31 Dec 2002 Volume: 10 Number: 4326
Today's topics:
Making input editable - Term::ReadLine <hgp@sbcglobal.net>
Re: Making input editable - Term::ReadLine (Anno Siegel)
Re: Making input editable - Term::ReadLine <hgp@sbcglobal.net>
Module to read Google usenet (groups) archive? (John Stumbles)
Re: Module to read Google usenet (groups) archive? <spam@thecouch.homeip.net>
Re: Module to read Google usenet (groups) archive? (Tad McClellan)
Re: Module to read Google usenet (groups) archive? <news@danielschroeer.de>
Re: Module to read Google usenet (groups) archive? <news@danielschroeer.de>
Need help with split <bigpun@mindspring.com>
Re: Need help with split (Helgi Briem)
Re: Need help with split (Tad McClellan)
Need to run command without waiting for results <longhorn101@hotmail.com>
Re: Need to run command without waiting for results <Graham.T.Wood@oracle.com>
Re: Need to run command without waiting for results <longhorn101@hotmail.com>
Re: Need to run command without waiting for results <usenet@atrixnet.com>
Re: Need to run command without waiting for results <jurgenex@hotmail.com>
Re: Need to run command without waiting for results <goldbb2@earthlink.net>
Passing an array to a subroutine (HM)
Re: Passing an array to a subroutine <nobull@mail.com>
Re: Passing an array to a subroutine (Tad McClellan)
Perl on Pocket PC 2002? <bobx@linuxmail.org>
Perl Tutorials <scott@neo.rr.com>
Re: Perl Tutorials <barryk2@SPAM-KILLER.mts.net>
Re: Perl Tutorials <mgjv@tradingpost.com.au>
Re: Perl Tutorials <nobody@dev.null>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 31 Dec 2002 14:25:40 GMT
From: Harry Putnam <hgp@sbcglobal.net>
Subject: Making input editable - Term::ReadLine
Message-Id: <m2bs329sf0.fsf@sbcglobal.net>
I've been stumbling around with attempts to write even a very simple
script where user input is editable. I'm told the module
Term::ReadLine or maybe Term::ReadLine::Gnu is the tool for this.
I've been told it is very simple to do and to just
`perldoc Term::ReadLine' and all will be clear.
Unfortunate for me the documentation is largely over my head, so I
look for an example I can understand and translate to my simple usage.
The script example given in Term::ReadLine docu is well above what I'm
after:
use Term::ReadLine;
my $term = new Term::ReadLine 'Simple Perl calc';
my $prompt = "Enter your arithmetic expression: ";
my $OUT = $term->OUT || \*STDOUT;
while ( defined ($_ = $term->readline($prompt)) ) {
my $res = eval($_), "\n";
warn $@ if $@;
print $OUT $res, "\n" unless $@;
$term->addhistory($_) if /\S/;
}
It makes a nice little calculator but the input lines are no more
editable than with `perl -e 'while(<>){print}'
I read it over (the full perldoc section) several times but really
can't make heads or tails of it.
The `->' symbols and mentions of using `methods' or `objects' leave
me very confused.
Google.groups searches with groups set to `comp*perl* and search string
of `Term::ReadLine' pull up quite a few hits but all seem to be much
more complex than what I'm after.
At least two, were people asking the same question I am but they
didn't get answers.
I'm looking for a really simple example of making an input line
editable with either vi or emacs like line editing key bindings.
Something like one gets when using the `read' function in a true korn
shell (not pdksh).
ksh93
read
<input>
The user input will be fully editable with vi like keybindings.
I want to accomplish something similar while perl reads
user input.
------------------------------
Date: 31 Dec 2002 20:26:28 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Making input editable - Term::ReadLine
Message-Id: <ausuhk$n4k$1@mamenchi.zrz.TU-Berlin.DE>
Harry Putnam <hgp@sbcglobal.net> wrote in comp.lang.perl.misc:
>
> I've been stumbling around with attempts to write even a very simple
> script where user input is editable. I'm told the module
> Term::ReadLine or maybe Term::ReadLine::Gnu is the tool for this.
> I've been told it is very simple to do and to just
> `perldoc Term::ReadLine' and all will be clear.
>
> Unfortunate for me the documentation is largely over my head, so I
> look for an example I can understand and translate to my simple usage.
>
> The script example given in Term::ReadLine docu is well above what I'm
> after:
>
> use Term::ReadLine;
> my $term = new Term::ReadLine 'Simple Perl calc';
> my $prompt = "Enter your arithmetic expression: ";
> my $OUT = $term->OUT || \*STDOUT;
> while ( defined ($_ = $term->readline($prompt)) ) {
> my $res = eval($_), "\n";
> warn $@ if $@;
> print $OUT $res, "\n" unless $@;
> $term->addhistory($_) if /\S/;
> }
> It makes a nice little calculator but the input lines are no more
> editable than with `perl -e 'while(<>){print}'
While the program above isn't perfect, it seems to demonstrate the
editing capabilities of Term::ReadLine quite well. You can use the
arrow keys to step through command history (up/down) and to change
the cursor location in the current line(left/right). Backspace erases
a character while other characters are inserted at the cursor position.
If this doesn't work for you, try setting the environment variable
PERL_RL to "Perl" or "Gnu". The documentation isn't too clear as to
under which conditions one of these is supposed to work, nor what the
difference would be, but these values are worth a try.
Anno
------------------------------
Date: Tue, 31 Dec 2002 23:57:58 GMT
From: Harry Putnam <hgp@sbcglobal.net>
Subject: Re: Making input editable - Term::ReadLine
Message-Id: <m23codeo6x.fsf@sbcglobal.net>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
> Harry Putnam <hgp@sbcglobal.net> wrote in comp.lang.perl.misc:
[...]
>> It makes a nice little calculator but the input lines are no more
>> editable than with `perl -e 'while(<>){print}'
>
> While the program above isn't perfect, it seems to demonstrate the
> editing capabilities of Term::ReadLine quite well. You can use the
> arrow keys to step through command history (up/down) and to change
> the cursor location in the current line(left/right). Backspace erases
> a character while other characters are inserted at the cursor position.
>
> If this doesn't work for you, try setting the environment variable
> PERL_RL to "Perl" or "Gnu". The documentation isn't too clear as to
> under which conditions one of these is supposed to work, nor what the
> difference would be, but these values are worth a try.
Aah... with your prompting I found the reason it didn't seem editable.
By editable I meant vi or emacs like line editing.
I didn't have Term::ReadLine::Gnu installed.
I saw no errors to that effect or the like, but just happened to
install it thinking it might be the package I was after. Then
running that script I see editing become possible, even though I made
no changes in the script.
Things like ^a to go to beginning of line etc, work with
Term::ReadLine::Gnu installed but not otherwise.
To verify this, I ran
mv \
/usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi/Term/ReadLine/Gnu.pm \
/usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi/Term/ReadLine/Gnu.pmX
Then running the script again. Those emacs like commands quit working.
------------------------------
Date: 30 Dec 2002 18:21:05 -0800
From: johndstumbles@aol.com (John Stumbles)
Subject: Module to read Google usenet (groups) archive?
Message-Id: <860b11bb.0212301821.1b8e1f83@posting.google.com>
[Excuse if this is a repeat post: my &%*^$) dialup connection timed
out as I posted the last one and I'm having to retype this all again
:-(]
I'm looking for a module or code to read Google usenet (groups)
archives, piecing together the separate pages Google splits threads
into when they exceed 10 messages, and splits messages into when they
exceed so many lines. (One could grab full message headers and ease
the processing work by following the 'Original Format' link for each
message.)
I've searched CPAN, Google's archives of comp.lang.perl* and the web
but haven't found anything. Am I missing something? (I gather
WWW::Search::Scraper::Google and Net::Google do not work with Google's
'groups' archive.) Or does anyone have any code that does this, or to
use as a starting point?
FWIW I want to be able to download threads I'm interested in for my
own reference offline (and maybe as a hedge against Google doing a
Deja :-)
tia
John Stumbles
[not at A.O.bloody'ell - email to forename dot surname at ntlworld dot
com]
-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
------------------------------
Date: Mon, 30 Dec 2002 22:29:23 -0500
From: Mina Naguib <spam@thecouch.homeip.net>
Subject: Re: Module to read Google usenet (groups) archive?
Message-Id: <3E110F13.9050007@thecouch.homeip.net>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
John Stumbles wrote:
| [Excuse if this is a repeat post: my &%*^$) dialup connection timed
| out as I posted the last one and I'm having to retype this all again
| :-(]
|
| I'm looking for a module or code to read Google usenet (groups)
| archives, piecing together the separate pages Google splits threads
| into when they exceed 10 messages, and splits messages into when they
| exceed so many lines. (One could grab full message headers and ease
| the processing work by following the 'Original Format' link for each
| message.)
|
| I've searched CPAN, Google's archives of comp.lang.perl* and the web
| but haven't found anything. Am I missing something? (I gather
| WWW::Search::Scraper::Google and Net::Google do not work with Google's
| 'groups' archive.) Or does anyone have any code that does this, or to
| use as a starting point?
|
| FWIW I want to be able to download threads I'm interested in for my
| own reference offline (and maybe as a hedge against Google doing a
| Deja :-)
It seems that you've done your homework. I don't have a direct answer
for you, but a while ago Google offered developers (via SOAP and a
unique developer key you apply for and get for free) the ability to
search their database. I don't know if that included the usenet
archives or just the web, you might want to look into that.
Best of luck.
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE+EQ8TeS99pGMif6wRApDuAJ99HdhlaKCRM2GHNGnDKHwr03RvBQCglmnL
zzQ6G74TS2Ek6pGlyyXzjrM=
=wyhD
-----END PGP SIGNATURE-----
------------------------------
Date: Mon, 30 Dec 2002 22:01:13 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Module to read Google usenet (groups) archive?
Message-Id: <slrnb125k9.67l.tadmc@magna.augustmail.com>
Mina Naguib <spam@thecouch.homeip.net> wrote:
> John Stumbles wrote:
>| I'm looking for a module or code to read Google usenet (groups)
>| archives,
> , but a while ago Google offered developers (via SOAP and a
> unique developer key you apply for and get for free) the ability to
> search their database. I don't know if that included the usenet
> archives or just the web, you might want to look into that.
It does not work for google groups:
http://www.google.com/apis/api_faq.html#ini2
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 31 Dec 2002 13:57:16 +0100
From: Daniel =?ISO-8859-15?Q?Schr=F6er?= <news@danielschroeer.de>
Subject: Re: Module to read Google usenet (groups) archive?
Message-Id: <aus47m$vd9$04$1@news.t-online.com>
John Stumbles wrote:
> I'm looking for a module or code to read Google usenet (groups)
Björn Höhrmann posted such a module in the german group
de.comp.lang.perl.misc.
<3e5c86f7.214018442@news.bjoern.hoehrmann.de>
You might be able to read the perl part of it.
Also notice that google's terms of service permit the usage of such
scripts.
ciao, Daniel.
------------------------------
Date: Tue, 31 Dec 2002 16:54:09 +0100
From: Daniel =?ISO-8859-15?Q?Schr=F6er?= <news@danielschroeer.de>
Subject: Re: Module to read Google usenet (groups) archive?
Message-Id: <2598930.76ZdvQCiDv@news.danielschroeer.de>
Daniel Schröer wrote:
> Also notice that google's terms of service permit the usage of such
> scripts.
"do not permit" that is.
------------------------------
Date: Mon, 30 Dec 2002 09:09:45 -0500
From: "Jim Janovich" <bigpun@mindspring.com>
Subject: Need help with split
Message-Id: <aupjv7$pe7$1@slb9.atl.mindspring.net>
Hello,
I have a string that looks like:
c:\folder1\folder2\folder3\blah.jpg
But the folders can be any number of folders. All I need is the last piece
(blah.jpg). Can someone help? I was going to split on \ but since there
can be any nuber of them I cannot figure it out. Any help would be
appreciated.
Thanks!
Jim
------------------------------
Date: Mon, 30 Dec 2002 14:17:30 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Need help with split
Message-Id: <3e1054d2.278473734@news.cis.dfn.de>
On Mon, 30 Dec 2002 09:09:45 -0500, "Jim Janovich"
<bigpun@mindspring.com> wrote:
>I have a string that looks like:
>c:\folder1\folder2\folder3\blah.jpg
>
>But the folders can be any number of folders. All I need is the last piece
>(blah.jpg). Can someone help? I was going to split on \ but since there
>can be any nuber of them I cannot figure it out. Any help would be
>appreciated.
#!/perl
use strict;
use warnings;
use File::Basename;
my $fullpath = 'c:\folder1\folder2\folder3\blah.jpg';
$fullpath =~ s:\\:\/:g; # correct the backslashes
my $basename = basename($fullpath);
print "$basename\n";
__END__
--
Regards, Helgi Briem
helgi AT decode DOT is
------------------------------
Date: Mon, 30 Dec 2002 09:08:04 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Need help with split
Message-Id: <slrnb10oak.4g8.tadmc@magna.augustmail.com>
Jim Janovich <bigpun@mindspring.com> wrote:
>
> I have a string that looks like:
>
> c:\folder1\folder2\folder3\blah.jpg
>
> All I need is the last piece
> (blah.jpg). Can someone help?
Use the File::Basename module.
You appear to be on Windows, so since
c:/folder1/folder2/folder3/blah.jpg
will also work on that system, you should use a module that
can handle either kind of directory separator.
> I was going to split on \ but since there
> can be any nuber of them I cannot figure it out.
You wouldn't do this for your actual problem, for that you
should use the module above.
But you can grab the last item from a split using a "list slice":
my $file = (split /\\/)[-1];
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 30 Dec 2002 20:04:58 GMT
From: "Jon" <longhorn101@hotmail.com>
Subject: Need to run command without waiting for results
Message-Id: <GF1Q9.505125$P31.162082@rwcrnsc53>
I am trying to figure out how to make perl execute a set of commands and not
wait for the results.
In Unix I do a (nohup command.exe &). But I am running Perl on a Win2K
machine. None of my perl books describe how to do this. Can anyone out
there tell me how to do this??
Thanks
------------------------------
Date: Mon, 30 Dec 2002 20:21:41 +0000
From: Graham Wood <Graham.T.Wood@oracle.com>
Subject: Re: Need to run command without waiting for results
Message-Id: <3E10AAD5.CA0FEF59@oracle.com>
Jon wrote:
> I am trying to figure out how to make perl execute a set of commands and not
> wait for the results.
> In Unix I do a (nohup command.exe &). But I am running Perl on a Win2K
> machine. None of my perl books describe how to do this. Can anyone out
> there tell me how to do this??
>
> Thanks
You could use
system("start command.exe");
which is a windows way of kicking off a command in another window. This will
return immediately with a return code of 0 or 1 depending on whether "start"
worked but won't tell you anything about how command.exe fared.
Alternatively, there is a more complicated method using the Win32::Process
module that is installed with ActiveState perl by default.
To use it:
use Win32::Process;
use Win32;
sub ErrorReport{
print Win32::FormatMessage( Win32::GetLastError() );
}
Win32::Process::Create($proc, "C:/path/to/command.exe",
"C:/path/to/command.exe argument1 argument2",
0,CREATE_NEW_CONSOLE,"C:/path/to/working/directory")
|| die ErrorReport();
$pid=$proc->GetProcessID();
if(Win32::Process::Open($openobj,$pid,0) != 0){
# your process started successfully
}
perldoc Win32::Process for details.
Hope this helps
Graham
------------------------------
Date: Mon, 30 Dec 2002 20:36:00 GMT
From: "Jon" <longhorn101@hotmail.com>
Subject: Re: Need to run command without waiting for results
Message-Id: <Q62Q9.384375$GR5.115411@rwcrnsc51.ops.asp.att.net>
Wow. I will try it out.
Thanks
"Graham Wood" <Graham.T.Wood@oracle.com> wrote in message
news:3E10AAD5.CA0FEF59@oracle.com...
> Jon wrote:
>
> > I am trying to figure out how to make perl execute a set of commands and
not
> > wait for the results.
> > In Unix I do a (nohup command.exe &). But I am running Perl on a Win2K
> > machine. None of my perl books describe how to do this. Can anyone
out
> > there tell me how to do this??
> >
> > Thanks
>
> You could use
>
> system("start command.exe");
>
> which is a windows way of kicking off a command in another window. This
will
> return immediately with a return code of 0 or 1 depending on whether
"start"
> worked but won't tell you anything about how command.exe fared.
>
> Alternatively, there is a more complicated method using the Win32::Process
> module that is installed with ActiveState perl by default.
>
> To use it:
>
> use Win32::Process;
> use Win32;
>
> sub ErrorReport{
> print Win32::FormatMessage( Win32::GetLastError() );
> }
>
>
> Win32::Process::Create($proc, "C:/path/to/command.exe",
> "C:/path/to/command.exe argument1 argument2",
> 0,CREATE_NEW_CONSOLE,"C:/path/to/working/directory")
> || die ErrorReport();
>
> $pid=$proc->GetProcessID();
>
> if(Win32::Process::Open($openobj,$pid,0) != 0){
> # your process started successfully
> }
>
> perldoc Win32::Process for details.
>
> Hope this helps
>
> Graham
>
------------------------------
Date: Mon, 30 Dec 2002 15:36:19 -0600
From: Tommy Butler <usenet@atrixnet.com>
To: Jon <longhorn101@hotmail.com>
Subject: Re: Need to run command without waiting for results
Message-Id: <3E10BC53.8020705@atrixnet.com>
Jon wrote:
> I am trying to figure out how to make perl execute a set of commands an=
d not
> wait for the results.
> In Unix I do a (nohup command.exe &). But I am running Perl on a Win2=
K
> machine. None of my perl books describe how to do this. Can anyone o=
ut
> there tell me how to do this??
>=20
> Thanks
fork() and don't waitpid()
--=20
-Tommy Butler
see if I'm online =BBhttp://ooopps.sourceforge.net/online
Tommy Butler <tommy@atrixnet.com>
phone: (817)-468-7716
6711 Forest Park Dr
Arlington, TX
76001-8403
Download my r=E9sum=E9 in PDF, MS Word, HTML, text
http://www.atrixnet.com/
the ooOPps Code Library
http://ooopps.sourceforge.net/pub/
------------------------------
Date: Tue, 31 Dec 2002 00:29:08 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Need to run command without waiting for results
Message-Id: <ox5Q9.26615$Jb.18833@nwrddc02.gnilink.net>
Jon wrote:
> I am trying to figure out how to make perl execute a set of commands
> and not wait for the results.
> In Unix I do a (nohup command.exe &). But I am running Perl on a
> Win2K machine. None of my perl books describe how to do this. Can
> anyone out there tell me how to do this??
A simple "fork" plus "exec" should do the job.
jue
------------------------------
Date: Tue, 31 Dec 2002 03:13:30 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Need to run command without waiting for results
Message-Id: <3E1151AA.B778F9B8@earthlink.net>
Graham Wood wrote:
[snip]
> sub ErrorReport{
> print Win32::FormatMessage( Win32::GetLastError() );
> }
Is there any reason to use these Win32:: thingies, instead of the much
simpler 'print $^E;' ?
> Win32::Process::Create($proc, "C:/path/to/command.exe",
> "C:/path/to/command.exe argument1 argument2",
> 0,CREATE_NEW_CONSOLE,"C:/path/to/working/directory")
> || die ErrorReport();
This essentially does die(print(...)). That seems wrong. It should
probably be:
Win32...Create(....) or die $^E;
or, if you like using lots of Win32:: functions:
Win32...Create(....)
or die Win32::FormatMessage( Win32::GetLastError() );
> $pid=$proc->GetProcessID();
>
> if(Win32::Process::Open($openobj,$pid,0) != 0){
> # your process started successfully
> }
The only reason to use Open() is if you have a $pid which you've read
from a file... After all, if the Create() call succeeds, then your
process *did* start successfully, and if the Create() call failed, then
you've die()d.
--
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);
------------------------------
Date: 31 Dec 2002 10:29:06 -0800
From: happyman_132000@yahoo.com (HM)
Subject: Passing an array to a subroutine
Message-Id: <71c71f98.0212311029.481d504d@posting.google.com>
I am having trouble passing an array into validateString subroutine
and then
walking through the array and comparing its contents. Could someone
please
take a look what I have and tell me what the problem is? I can't
believe how
much trouble I am having with something simple. Thank you.
This is my .pl file
## passes in array contain 4 elements (each a string) and the size of
the array
$Response = Validation::validateString(@Strings, $Size);
####################################################
This is my .pm file
sub validateString
{
# my $self = shift;
(@a_String, $ArraySize) = shift;
## Possible strings
my $ValidString1 = "This is a test.";
my $ValidString2 = "This line is contained in the file.";
my $ValidString3 = "So is this one.";
my $ValidString4 = "And this one too.";
## For some reason I have to decrement 2 times, otherwise
## the for loop runs two additional times???
$ARRAYSIZE--;
$ARRAYSIZE--;
## Does not continue past the 0th element in the array (first
string)
for($i=0; $i<=$ArraySize; $i++)
{
## This one checks ok. Which it should not.
## Check for string1
if($a_String[$i] =~ $ValidString1){print"Expected String :
$a_String[$i]\n";}
## Check for string2
elsif($a_String[$i] =~ $ValidString2){print"Expected String
: $a_String[$i]\n";}
## Check for string3
elsif($a_String[$i] =~ $ValidString3){print"Expected String
: $a_String[$i]\n";}
## Check for string4
elsif($a_String[$i] =~ $ValidString4){print"Expected String
: $a_String[$i]\n";}
## Does not catch ValidString1.
## Reponse does not match any strings
elsif($a_String[$i] !~ $ValidString1 or $a_String[$i] !~
$ValidString2 or $a_String[$i] !~ $ValidString3 or $a_String[$i] !~
$ValidString4)
{
print"Unexpected String found in file : $a_String[$i]";
}
}
}
1;
################################################
This what is contained in the array:
This is a test. Not a valid string.
This line is contained in the file.
So is this one.
And this one too.
------------------------------
Date: 31 Dec 2002 18:58:54 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Passing an array to a subroutine
Message-Id: <u9adimc8wh.fsf@wcl-l.bham.ac.uk>
happyman_132000@yahoo.com (HM) writes in alternately long and short
lines which makes me sea-sick:
> I am having trouble passing an array
See FAQ: "How can I pass/return a {Function, FileHandle, Array,
Hash, Method, Regex}?"
> into validateString subroutine and then walking through the array
> and comparing its contents. Could someone please take a look what I
> have and tell me what the problem is?
> ## passes in array contain 4 elements (each a string) and the size of
> the array
> $Response = Validation::validateString(@Strings, $Size);
Why pass the size of the array? This isn't C. In Perl you can get
the size of an array trivially by just by using the array in a scalar
context.
> sub validateString
> {
> (@a_String, $ArraySize) = shift;
What do you thing shift does? Compare what "perldoc -f shift" says.
BTW: You forgot the 'my'. Did you perhaps forget to enable warnings
and strictures?
You probably were thinking:
my (@a_String, $ArraySize) = @_;
But... arrays on the LHS of a list assignment are greedy. $ArraySize
will always be undef.
my $ArraySize = pop;
my @a_String = @_;
But then again there's no point passing the size. But see the FAQ
anyhow - you probably should be passing a reference.
>
> ## Possible strings
> my $ValidString1 = "This is a test.";
> my $ValidString2 = "This line is contained in the file.";
> my $ValidString3 = "So is this one.";
> my $ValidString4 = "And this one too.";
If you ever find yourself declaring a set of similarly named variables
big alarm bells should ring in your head and the word "array" should
flash in you minds-eye so brightly that it causes you pain.
Posting code like that here certainly causes us pain.
> ## For some reason I have to decrement 2 times, otherwise
> ## the for loop runs two additional times???
> $ARRAYSIZE--;
> $ARRAYSIZE--;
$ARRAYSIZE and $ArraySize are different. Did you perhaps "forget" to
enable warnings and strictures?
> ## Does not continue past the 0th element in the array (first
> string)
> for($i=0; $i<=$ArraySize; $i++)
This isn't C. In Perl you can simply iterate over a list.
for my $string ( @a_String )
BTW: You forgot the 'my'. Did you perhaps forget to enable warnings
and strictures?
> {
> ## This one checks ok. Which it should not.
> ## Check for string1
> if($a_String[$i] =~ $ValidString1){print"Expected String :
> $a_String[$i]\n";}
Are you are using '=~' where you mean to use 'eq' or do you really use
the vaiable name $ValidString1 for a vaiable that contains a regular
expression?
> ## Check for string2
> elsif($a_String[$i] =~ $ValidString2){print"Expected String
> : $a_String[$i]\n";}
[snip same again 2 more times ]
If you'd used an array you could have used a loop rather than write
the same code 4 times.
> ## Reponse does not match any strings
> elsif($a_String[$i] !~ $ValidString1 or $a_String[$i] !~
> $ValidString2 or $a_String[$i] !~ $ValidString3 or $a_String[$i] !~
> $ValidString4)
Errr... given that you already know $a_String[$i] did not match any of
those regular expressions you can simpify that to:
elsif ( 1 or 1 or 1 or 1 )
Or even just:
else
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Tue, 31 Dec 2002 17:25:31 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Passing an array to a subroutine
Message-Id: <slrnb149rb.9h2.tadmc@magna.augustmail.com>
HM <happyman_132000@yahoo.com> wrote:
> I can't
> believe how
> much trouble I am having with something simple.
Since you didn't:
check the Perl FAQ (perldoc -q pass)
check the docs for subroutines (perldoc perlsub)
enable warnings
enable strictures
I have no trouble at all believing how much trouble you are having.
:-)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 31 Dec 2002 01:10:52 GMT
From: "Bob X" <bobx@linuxmail.org>
Subject: Perl on Pocket PC 2002?
Message-Id: <w86Q9.1085$Fj2.690199@news2.news.adelphia.net>
Is there a version that runs on the Pocket PC?
Bob
------------------------------
Date: Tue, 31 Dec 2002 07:02:21 GMT
From: "Scott Hoopes" <scott@neo.rr.com>
Subject: Perl Tutorials
Message-Id: <1ibQ9.41963$%3.10348250@twister.neo.rr.com>
Hello,
I want to learn how to code in PERL. What are some good books/tutorials to
go through to understand the introductory programming necessities for PERL.
Thanks in advance.
- Scott Hoopes
------------------------------
Date: Tue, 31 Dec 2002 08:15:11 -0600
From: Barry Kimelman <barryk2@SPAM-KILLER.mts.net>
Subject: Re: Perl Tutorials
Message-Id: <MPG.187b626da96b14479896b9@news.mts.net>
[This followup was posted to comp.lang.perl.misc and a copy was sent to
the cited author.]
In article <1ibQ9.41963$%3.10348250@twister.neo.rr.com>, Scott Hoopes
(scott@neo.rr.com) says...
> Hello,
>
> I want to learn how to code in PERL. What are some good books/tutorials to
> go through to understand the introductory programming necessities for PERL.
>
> Thanks in advance.
>
> - Scott Hoopes
>
>
>
There are 2 good books published by The O'Reilly company
(1) a book known as "the Camel" (due to the camel on the front cover)
"Programming Perl" - this ia a language reference manual
(2) a book known as "the lama" (due to the lama on the front cover)
(I forget the exact title, something like Learning to Program in
Perl). - this is a Perl programming manual
Check out http://www.perl.com
--
---------
Barry Kimelman
Winnipeg, Manitoba, Canada
email : bkimelman@hotmail.com
------------------------------
Date: Wed, 1 Jan 2003 01:15:44 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Perl Tutorials
Message-Id: <slrnb139kg.4tt.mgjv@martien.heliotrope.home>
On Tue, 31 Dec 2002 07:02:21 GMT,
Scott Hoopes <scott@neo.rr.com> wrote:
> Hello,
>
> I want to learn how to code in PERL. What are some good books/tutorials to
> go through to understand the introductory programming necessities for PERL.
First of all, it's Perl.
If you are not a programmer yet, and you want to learn programming as
well as Perl, give Andrew Johnson's /Elements of Programming with Perl/
a shot.
If you are already a programmer, try /Learning Perl/, by Randal Schwartz
and Tom Phoenix.
Martien
--
|
Martien Verbruggen | Useful Statistic: 75% of the people make up
| 3/4 of the population.
|
------------------------------
Date: Tue, 31 Dec 2002 14:35:41 GMT
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: Perl Tutorials
Message-Id: <3E11AA7E.7010008@dev.null>
Scott Hoopes wrote:
> I want to learn how to code in PERL. What are some good books/tutorials to
> go through to understand the introductory programming necessities for PERL.
perlfaq2 (available, for instance, at
http://www.perldoc.com/perl5.6/pod/perlfaq2.html) offers a lot of good
advice. While you are there, take a look of the rest of perlfaq by
visiting http://www.perldoc.com/perl5.6/pod/perlfaq.html
------------------------------
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.
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 V10 Issue 4326
***************************************