[28119] in Perl-Users-Digest
Perl-Users Digest, Issue: 9483 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jul 16 21:05:59 2006
Date: Sun, 16 Jul 2006 18:05:04 -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 Sun, 16 Jul 2006 Volume: 10 Number: 9483
Today's topics:
Re: A simply regex question <sbryce@scottbryce.com>
creating variable names within a perl script <bdalzell@qis.net>
Re: creating variable names within a perl script <rvtol+news@isolution.nl>
Re: creating variable names within a perl script <jurgenex@hotmail.com>
Re: creating variable names within a perl script <someone@example.com>
Re: How get UTF-8 from urlencoded web form <noreply@gunnar.cc>
Re: How get UTF-8 from urlencoded web form <rvtol+news@isolution.nl>
Re: How get UTF-8 from urlencoded web form <bart@nijlen.com>
Re: How get UTF-8 from urlencoded web form <1usa@llenroc.ude.invalid>
Re: How get UTF-8 from urlencoded web form <rvtol+news@isolution.nl>
Re: How get UTF-8 from urlencoded web form robic0
Re: How to local-ly close a handle? <benmorrow@tiscali.co.uk>
Module::Build / version / cpan / tail chasing <skendric@fhcrc.org>
Net::Telnet - Library Application <laff7430@bellsouth.net>
Re: Net::Telnet - Library Application <rvtol+news@isolution.nl>
Re: Parse data structure <benmorrow@tiscali.co.uk>
Re: Perl equivalent of this script? <tadmc@augustmail.com>
simulate user activity <daleif@imf.au.dk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 16 Jul 2006 18:43:00 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: A simply regex question
Message-Id: <oPednbMlQ-qMQCfZnZ2dnUVZ_oadnZ2d@comcast.com>
Franzl Wisseworst wrote:
> [..]
>
>
>>>>Your task can better be solved without using a RE.
>
>
> If I only knew how to...
http://perldoc.perl.org/functions/index.html
------------------------------
Date: 16 Jul 2006 12:14:25 -0700
From: "bdz" <bdalzell@qis.net>
Subject: creating variable names within a perl script
Message-Id: <1153077265.696677.41420@m79g2000cwm.googlegroups.com>
This has been bothering me for years and I think my problem is I do not
know the proper way to ask the question.
Say I want to create an open ended set of variables - I do not know how
many I will have when the script asks me to start entering them.
so i can do something like this:
while (-1){
print "enter a variable: ";
$var =<STDIN>;
chomp($var);
# what i want to do at this point is give this variable a name such
# as $var1, then when the loop comes around again I would like
# to be able to give the next variable a different name but since
# I do not know how many are being entered i cannot create the
# names ahead of time. is there anyway to create variable
# names on the fly in perl ?
exit if $var eq '-1
}
------------------------------
Date: Sun, 16 Jul 2006 21:24:23 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: creating variable names within a perl script
Message-Id: <e9ear6.140.1@news.isolution.nl>
bdz schreef:
> This has been bothering me for years and I think my problem is I do
> not know the proper way to ask the question.
>
> Say I want to create an open ended set of variables - I do not know
> how many I will have when the script asks me to start entering them.
>
> so i can do something like this:
>
> while (-1){
> print "enter a variable: ";
> $var =<STDIN>;
> chomp($var);
>
> # what i want to do at this point is give this variable a name such
> # as $var1, then when the loop comes around again I would like
> # to be able to give the next variable a different name but since
> # I do not know how many are being entered i cannot create the
> # names ahead of time. is there anyway to create variable
> # names on the fly in perl ?
>
> exit if $var eq '-1
> }
Use an array? perldoc -f push
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Sun, 16 Jul 2006 19:33:20 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: creating variable names within a perl script
Message-Id: <4wwug.3117$Lw.774@trnddc07>
bdz wrote:
> so i can do something like this:
>
> while (-1){
> print "enter a variable: ";
> $var =<STDIN>;
> chomp($var);
>
> # what i want to do at this point is give this variable a name such
> # as $var1, then when the loop comes around again I would like
> # to be able to give the next variable a different name but since
> # I do not know how many are being entered i cannot create the
> # names ahead of time. is there anyway to create variable
> # names on the fly in perl ?
Technically this is possible (it is known as symbolic references), but it is
is highly inadvisable. Check the FAQ
perldoc -q "variable name"
or the gazillions of previous postings on this topic for details.
In your particular case why don't you simply use an array? You don't even
have to keep track of the current index, because in
$arr[@arr] = <STDIN>;
@arr will be evaluated to the number of elements in the array which happens
to be one larger than the index of the currently last element and thus
exactly the index you need to place the next element.
jue
------------------------------
Date: Sun, 16 Jul 2006 22:11:03 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: creating variable names within a perl script
Message-Id: <XPyug.50197$B91.12649@edtnps82>
Jürgen Exner wrote:
> bdz wrote:
>>so i can do something like this:
>>
>>while (-1){
>> print "enter a variable: ";
>> $var =<STDIN>;
>> chomp($var);
>>
>># what i want to do at this point is give this variable a name such
>># as $var1, then when the loop comes around again I would like
>># to be able to give the next variable a different name but since
>># I do not know how many are being entered i cannot create the
>># names ahead of time. is there anyway to create variable
>># names on the fly in perl ?
>
> Technically this is possible (it is known as symbolic references), but it is
> is highly inadvisable. Check the FAQ
> perldoc -q "variable name"
> or the gazillions of previous postings on this topic for details.
>
> In your particular case why don't you simply use an array? You don't even
> have to keep track of the current index, because in
> $arr[@arr] = <STDIN>;
> @arr will be evaluated to the number of elements in the array which happens
> to be one larger than the index of the currently last element and thus
> exactly the index you need to place the next element.
Or just use push:
push @arr, scalar <STDIN>;
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sun, 16 Jul 2006 20:08:41 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How get UTF-8 from urlencoded web form
Message-Id: <4hvdkdF1bq7bU1@individual.net>
Bart Van der Donck wrote:
> Gunnar Hjalmarsson wrote:
>>The browser automatically URI escapes 'unsafe' characters when you make
>>a GET or an x-www-form-urlencoded POST request. Hence those characters
>>need to be unescaped by the web server. CGI.pm as well as other modules
>>for parsing CGI data takes care of that.
>
> #!/usr/bin/pedant
> I think the correct terminology is actually URL-encoding here (or
> percent-encoding) in stead of URI-escaping
> (http://en.wikipedia.org/wiki/URL_encoding).
I simply chose to use the term from URI::Escape. My English isn't good
enough for arguing about it. ;-)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sun, 16 Jul 2006 20:44:40 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: How get UTF-8 from urlencoded web form
Message-Id: <e9e8v1.1e0.1@news.isolution.nl>
Bart Van der Donck schreef:
> You can't compare (n vs. \n) to (é vs. %E9).
You can compare (<LF> vs. "\n") to (<é> vs. "%E9"). Often, such
translations use a table in memory.
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: 16 Jul 2006 13:45:10 -0700
From: "Bart Van der Donck" <bart@nijlen.com>
Subject: Re: How get UTF-8 from urlencoded web form
Message-Id: <1153082709.987475.176030@m79g2000cwm.googlegroups.com>
Dr.Ruud wrote:
> Bart Van der Donck schreef:
>
> > You can't compare (n vs. \n) to (=E9 vs. %E9).
>
> You can compare (<LF> vs. "\n") to (<=E9> vs. "%E9"). Often, such
> translations use a table in memory.
Yes, exactly, like:
LF -> %0A
=E9 -> %E9
<LF> refers to hex 0A by definition, but I'm not sure whether "\n"
always refers to hex 0A on various operating systems.
--=20
Bart
------------------------------
Date: Sun, 16 Jul 2006 20:56:31 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: How get UTF-8 from urlencoded web form
Message-Id: <Xns9802AC6FFCD31asu1cornelledu@127.0.0.1>
"Bart Van der Donck" <bart@nijlen.com> wrote in
news:1153070852.318555.265370@75g2000cwc.googlegroups.com:
[ You should not snip attributions. You create the impression that I
wrote something I did not. That is not nice. ]
> A. Sinan Unur wrote:
>
>> > There is no encoding involved in \n, but there is when you write é
>> > as %E9
[ You made the statement above. I did not. ]
>> That does not make sense. 'n' all by itself is not the end of line
>> character anywhere. In the realm of Perl's interpolates strings, the
>> letter 'n' that follows '\' is the encoding of the EOL.
>
> You can't compare (n vs. \n) to (é vs. %E9). There is simply no
> relation between the characters that are represented by "n" and "\n".
> There is no encoding or conversion or whatever.
This is absurd. "\n" is an encoding of EOL.
Since you like quoting Wikipedia:
<http://en.wikipedia.org/wiki/Encoding>
<blockquote>
Encoding is the process of transforming information from one format into
another. The opposite operation is called decoding.
</blockquote>
Any mapping of one thing on to another is an encoding.
This is getting tedious. I am out of this thread.
> table. There is no "going from" involved in "n" versus "\n".
Sinan
--
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://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Sun, 16 Jul 2006 23:33:27 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: How get UTF-8 from urlencoded web form
Message-Id: <e9eime.1bs.1@news.isolution.nl>
Bart Van der Donck schreef:
> Dr.Ruud:
>> Bart Van der Donck:
>>> You can't compare (n vs. \n) to (é vs. %E9).
>>
>> You can compare (<LF> vs. "\n") to (<é> vs. "%E9"). Often, such
>> translations use a table in memory.
>
> Yes, exactly, like:
> LF -> %0A
> é -> %E9
>
> <LF> refers to hex 0A by definition,
Yes, but when going the other way around, "%E9" can be translated to <é>
(if that's what the character is at position 0xE9 in the current
charset), and "\n" to LF (or CR or CRLF or whatever, depending on the
platform). That the "%E9" and 0xE9 look a lot alike, and "\n" and 0x0A
don't, doesn't really matter.
If the current charset is UTF-8, the "%E9" is translated to a specific
multibyte sequence. In this context of escape characters, you could say
that UTF-8 has an escape bit.
If the current charset is ASCII, the "%E9" might be translated to "?" or
"e", or "'e" or "e'" or whatever is feasible.
> but I'm not sure whether "\n"
> always refers to hex 0A on various operating systems.
It doesn't, but that doesn't matter. The escape-character, at the start
of the escape sequence, brings up a special mode, that just eats the
escape-sequence and inserts/returns an equally or more specific
translation.
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Sun, 16 Jul 2006 18:03:38 -0700
From: robic0
Subject: Re: How get UTF-8 from urlencoded web form
Message-Id: <0vllb2lc8gcfofhflm6s6dp92cpjn0meh1@4ax.com>
On Sun, 16 Jul 2006 20:56:31 GMT, "A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote:
>"Bart Van der Donck" <bart@nijlen.com> wrote in
>news:1153070852.318555.265370@75g2000cwc.googlegroups.com:
>
>[ You should not snip attributions. You create the impression that I
>wrote something I did not. That is not nice. ]
>
>> A. Sinan Unur wrote:
>>
>>> > There is no encoding involved in \n, but there is when you write é
>>> > as %E9
>
>[ You made the statement above. I did not. ]
>
>>> That does not make sense. 'n' all by itself is not the end of line
>>> character anywhere. In the realm of Perl's interpolates strings, the
>>> letter 'n' that follows '\' is the encoding of the EOL.
>>
>> You can't compare (n vs. \n) to (é vs. %E9). There is simply no
>> relation between the characters that are represented by "n" and "\n".
>> There is no encoding or conversion or whatever.
>
>This is absurd. "\n" is an encoding of EOL.
>
>Since you like quoting Wikipedia:
><http://en.wikipedia.org/wiki/Encoding>
>
><blockquote>
>Encoding is the process of transforming information from one format into
>another. The opposite operation is called decoding.
></blockquote>
>
>Any mapping of one thing on to another is an encoding.
>
>This is getting tedious. I am out of this thread.
>
>> table. There is no "going from" involved in "n" versus "\n".
>
>Sinan
The definition of "encoding" from wikipedia is a broad definition.
For example encoding/decoding digital media, say mpeg2 involve a
linear language to, on the encoding side, take out redundency in
adjacent frames, then reconstruct the full frames on the decoding side.
The jpeg compression layer is on top of the mpeg layer. Finally a full
bitmap frame. This is by default the wikipedia definition. This is macro.
In the case of a single document character, its a either/or argument.
Either the character is escaped, in which case it loses its binary form
or its not, in which case it retains it.
There's a "reason" why certain Unicode characters are reserved as control
codes. Here is the reason: THE DATA TRANSFERED ON ALL COMPUTERS ARE BINARY.
There is no spoon Neo, there is no spoon.
I guess in that sence, all files read/written are encoded/decoded.
The formula for encoding is the same as decoding. Think of it as a train
of boxcars. The decoder waits for the marker cars, then grabs the next
series of cars as its formula requires. Those cars grabbed are then sent
on to the next decoder (possibly the same one) where finite smaller cars
are extracted. The itteration continues (possibly several times).
All for what? The first thing done was to standardize on how many bytes in a Unicode char
(there may be small/big). Then the encoding, but what is an encoding statement?
Why its nothing more that an offset into a binary blob of data that contains the
"character bitmap" to display. Of course displaying a different encoding bitmaped characters
doesn't translate into a language translator. The only thing the Rossetta Stone did was
to connect alphabet characters across languages, ie: it didn't do language translation.
Back to the larger issue of html/xml encoding/decoding, and I don't know what the
OP had in mind (looks like html/xml embedded url's) but he would seem to have to
know ahead of time how many times a parser will itterate his data and how many
times and what he needs to escape it.
The idea of an argument on encoding/decoding as it relates to charactersets is just
absurd! Encoding/Decoding was not only done on the very first computer display device
but is a concept over 4,000 years old!
Don't make this extremely simple concept out to be something just invented.
robic0
-get ur act together
his case, given that
------------------------------
Date: Mon, 17 Jul 2006 00:55:49 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: How to local-ly close a handle?
Message-Id: <590ro3-rgr.ln1@osiris.mauzo.dyndns.org>
Quoth "Ferry Bolhar" <bol@adv.magwien.gv.at>:
> kj:
>
> > I know of ways to temporarily silence STDERR that actually work,
> > but none of them begins to approach the simplicity of any of the
> > examples above. Any suggestions?
>
> Yes. How about:
>
> system 'crazystuff 2>/dev/null';
>
> Localizing STDERR with whatever has no impact on child processes,
> because the parent process' STDERR (which the child inherits) still
> remains open.
This is mostly just being picky :), but that would be better as
Localizing STDERR has no impact on child processes, because the parent
process' file-descriptor 2 (which the child inherits) remains open.
The point being that the confusion here is between Perl's STDERR and
perl's fd #2.
> It will have an impact when you do a "print STDERR"
> or somewhat similar, but it's meaningful with Perl commands only.
>
> And although you can localize a typeglob (and its associated IO handle),
> you can't localize a close! So if you close a file (as you did with "close
> STDERR"), the file will remain closed, even when leaving the block!
The fd you closed will remain closed, but the Perl filehandle will
revert to pointing to its old fd, and thus will be open again. :)
Ben
--
The Earth is degenerating these days. Bribery and corruption abound.
Children no longer mind their parents, every man wants to write a book,
and it is evident that the end of the world is fast approaching.
Assyrian stone tablet, c.2800 BC benmorrow@tiscali.co.uk
------------------------------
Date: 16 Jul 2006 16:09:09 -0700
From: "sbk" <skendric@fhcrc.org>
Subject: Module::Build / version / cpan / tail chasing
Message-Id: <1153091349.403503.231280@35g2000cwc.googlegroups.com>
hi,
i've compiled perl-5.8.8 from scratch (my favorite approach) ...
installed it ... and now i'm installing the modules which my in-house
collection of code requires ... and i've run into a 'loop' between
'version' and 'Module::Build' ... each requires the other ... and
'cpan' doesn't seem to know how to work around this:
cpan > install version
[...]
version-0.64/META.yml
version-0.64/MANIFEST
Removing previously used /home/skendric/.cpan/build/version-0.64
Package came without SIGNATURE
CPAN.pm: Going to build J/JP/JPEACOCK/version-0.64.tar.gz
This module requires Module::Build to install itself.
Install Module::Build from CPAN? [y] y
[...]
Module-Build-0.2803/t/xs.t
Removing previously used /home/skendric/.cpan/build/Module-Build-0.2803
WARNING: This key is not certified with a trusted signature!
Primary key fingerprint: ADCB DB05 B40E B2A2 A555 5462 82BB CC04 B7EF
9476
CPAN.pm: Going to build K/KW/KWILLIAMS/Module-Build-0.2803.tar.gz
Base class package "version" is empty.
(Perhaps you need to 'use' the module which defines that package
first.)
at lib/Module/Build/Version.pm line 2
BEGIN failed--compilation aborted at lib/Module/Build/Version.pm line
2.
Compilation failed in require at lib/Module/Build/ModuleInfo.pm line
11.
[...]
Compilation failed in require at Makefile.PL line 6.
BEGIN failed--compilation aborted at Makefile.PL line 6.
Running make test
CPAN: YAML loaded ok
---- Unsatisfied dependencies detected during
[K/KW/KWILLIAMS/Module-Build-0.280
3.tar.gz] -----
version
Running make install
Delayed until after prerequisites
Running install for module version
Running make for J/JP/JPEACOCK/version-0.64.tar.gz
[...]
version-0.64/MANIFEST
Removing previously used /home/skendric/.cpan/build/version-0.64
Package came without SIGNATURE
CPAN.pm: Going to build J/JP/JPEACOCK/version-0.64.tar.gz
This module requires Module::Build to install itself.
Install Module::Build from CPAN? [y]
at this point, i'm chasing my tail ... any tips on how to break out and
make progress?
--sk
stuart kendrick
fhcrc
------------------------------
Date: Sun, 16 Jul 2006 19:03:43 -0400
From: Carl Lafferty <laff7430@bellsouth.net>
Subject: Net::Telnet - Library Application
Message-Id: <mAzug.3368$iP1.2802@bignews2.bellsouth.net>
I have a problem with something I am doing using net::telnet in perl.
I am trying to write a script that will access an automated library
system via telnet and basically mimic what the company that sold us the
system did in VB. I am basically reverse engineering their code only in
perl.. anyway... My problem is that I am having to search for
different flags using waitfor. sometimes it is the word Description,
sometimes it is \x8f (I have no idea why but they seem to use that as a
delimiter quite often) My problem is that when I get to a particular
piece of data, I am not getting everything from the stream in my waitfor
variable.
This is a snippit of the code
#cleaning out the buffer
($info) = $galaxy->waitfor("/\x8f/");
print "1 $info\n";
($info) = $galaxy->waitfor("/\x8f/");
print "2 $info\n";
$galaxy->print("5000 5018 30 0 0 ");
($info) = $galaxy->waitfor("/\x8f/");
$info =~ s/\\b/\n/g;
$info =~ s/\\B/\<b\>/g;
$info =~ s/\n/\<\/b\>\n/g;
print "$info\n";
($info) = $galaxy->waitfor("/Description/");
$info =~ s/\\b/\n/g;
$info =~ s/\\B/\<b\>/g;
$info =~ s/\n/\<\/b\>\n/g;
print "$info\n";
#got stuff up to description now
($info) = $galaxy->waitfor("/\x5C\x62/");
$info =~ s/\\b/\n/g;
$info =~ s/\\B/\<b\>/g;
$info =~ s/\n/\<\/b\>\n/g;
print "Description: $info\n";
print "\nLogging out of galaxy\n";
#$ok = $galaxy->waitfor("/\x8f/");
$ok = $galaxy->print("999");
$ok = $galaxy->print("0005 GALAXY||20");
$ok = $galaxy->print("0010 ");
$galaxy->close;
-----------------------------------
0x000e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0x000f0: 20 5c 62 20 20 54 79 70 65 2f 6c 61 6e 67 75 61 \b
Type/langua
0x00100: 67 65 3a 20 5c 42 42 6f 6f 6b 2f 65 6e 67 5c 62 ge:
\BBook/eng\b
0x00110: 0d 20 20 20 49 53 42 4e 2f 49 53 53 4e 3a 20 5c .
ISBN/ISSN: \
0x00120: 42 2f 5c 62 0d 20 44 65 73 63 72 69 70 74 69 6f B/\b.
Descriptio
0x00130: 6e 3a 20 5c 42 31 37 38 20 70 2e 2c 20 32 30 20 n: \B178 p.. 20
0x00140: 63 6d 2e 20 20 20 20 20 20 20 20 20 5c 62 cm. \b
0x00000: 39 39 39 0d 999.
0x00000: 30 30 30 35 20 47 41 4c 41 58 59 7c 7c 32 30 0d 0005
GALAXY||20.
0x00000: 30 30 31 30 20 0d 0010 .
----------------------------------------------
above is the dump file (a little difficult to read :( )
it SEES the word description and gives me the info up to that.. BUT
after description the delimiter is \b (\x5c\x62) which is what I do a
waitfor on. all I get is a \
Everything after 0x00140: is my program signing out of the telnet session..
Any way to get that information into my variable?? Ive been beating my
head for 4 days now... any help is appreciated.
Carl Lafferty
System Admin
Floyd County Public Library
Prestonsburg, KY
------------------------------
Date: Mon, 17 Jul 2006 01:41:12 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Net::Telnet - Library Application
Message-Id: <e9epup.1cg.1@news.isolution.nl>
Carl Lafferty schreef:
> #got stuff up to description now
> ($info) = $galaxy->waitfor("/\x5C\x62/");
Because of unexpected interpolation, that could change to "/\b/" to
match backspace.
Maybe use a compiled regex:
($info) = $galaxy->waitfor(qr/\x5C\x62/);
Or try:
($info) = $galaxy->waitfor('/\\\b/');
(single or double quotes, 3 or 4 backslashes)
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Mon, 17 Jul 2006 00:45:12 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: Parse data structure
Message-Id: <8lvqo3-rgr.ln1@osiris.mauzo.dyndns.org>
Quoth Bob Walton <see.sig@rochester.rr.com>:
> Davidcollins001@gmail.com wrote:
> > This is my data structure that I am playing around with in a separate
> > file:
> >
> > may => [
> > [2,'train',20.00, 'expensive'],
> > [6,'train',15],
> > [19,'car',18,'best way']
> > ],
> > june => [
> > [5,'car',2.00],
> > [9,'train',1],
> > [19,'cat',18,'best way']
> > ],
> > july => [
> > [14,'plane',100],
> > [23,'boat',20]
> > ],
>
> Well, if you want to make your data files be Perl code, make it
> valid Perl, something like:
>
> $HoLoL={
> may => [
> [2,'train',20.00, 'expensive'],
> [6,'train',15],
> [19,'car',18,'best way']
> ],
> june => [
> [5,'car',2.00],
> [9,'train',1],
> [19,'cat',18,'best way']
> ],
> july => [
> [14,'plane',100],
> [23,'boat',20]
> ],
> };
>
> Then you can write a Perl program to execute this data file as
> follows, taking advantage of an already-written module to print
> the data structure (which module, incidentally, generates valid
> Perl code):
>
> use strict;
> use warnings;
> our $HoLoL;
> do 'junk566.txt';
> use Data::Dumper;
> print Dumper($HoLoL);
You can also avoid having to have the name of the variable in the file
(generally a good idea: firstly data files shouldn't need to know what
variables in the program they will be read into; secondly it means you
don't need to use a global, which is always a good thing):
#!/usr/bin/perl -l
use strict;
use warnings;
use Data::Dump qw/dump/; # I prefer this to Data::Dumper
my $HoLoL = { do "junk566.txt" };
print dump $HoLoL;
__END__
Note that this technique, while powerful, is not terribly safe. It's
basically equivalent to string eval, so all the caveats of that apply.
You don't get very clear error messages if the file contains syntax
errors, and dealing with this is somewhat tricky. More importantly, it
is possible to muck up anything in the program with an incorrect or
malicious data file, which leads to difficult-to-find bugs and security
holes (where that is important).
For an alternative way of creating data files which mimic the Perl
structures they read into, try YAML. For example:
travel.yml:
july:
-
- 14
- plane
- 100
-
- 23
- boat
- 20
june:
-
- 5
- car
- 2
-
- 9
- train
- 1
-
- 19
- cat
- 18
- best way
may:
-
- 2
- train
- 20
- expensive
-
- 6
- train
- 15
-
- 19
- car
- 18
- best way
Then write something like:
#!/usr/bin/perl -l
use strict;
use warnings;
use YAML;
use Data::Dump qw/dump/;
my $h = YAML::LoadFile 'travel.yml';
print dump $h;
__END__
It is possible to write YAML in a more Perlish style, like
{
may: [
[2, train, expensive],
[6, train, 15]
]
}
but YAML.pm currently doesn't seem to load these. YAML::Syck (which is
based on libsyck, written in C) does, but I can't seem to make it emit
them, if that's a concern for you. See
http://yaml4r.sourceforge.net/cookbook/ for an intro: don't worry that
it's for Ruby, most of the syntax is the same as Perl.
Ben
--
Like all men in Babylon I have been a proconsul; like all, a slave ... During
one lunar year, I have been declared invisible; I shrieked and was not heard,
I stole my bread and was not decapitated.
~ benmorrow@tiscali.co.uk ~ Jorge Luis Borges, 'The Babylon Lottery'
------------------------------
Date: Sun, 16 Jul 2006 15:13:33 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Perl equivalent of this script?
Message-Id: <slrnebl7fd.p85.tadmc@magna.augustmail.com>
george.varsamopoulos@gmail.com <george.varsamopoulos@gmail.com> wrote:
> i didn't find
You didn't even look in the Perl FAQ? That's not very nice.
perldoc -q HTML
How do I fetch an HTML file?
><?php
> $url = "http://yes.yes.yes/?arg=".$argv[1];
> if (($ff = fopen($url, "r"))==NULL) exit();
> while (!feof($ff)){
> $line = fgets($ff,512);
> printf("%s", $line);
> }
> fclose($ff);
> ?>
> ## Is there a short Perl script to replace this PHP script? ##
use LWP::Simple;
my $url = 'http://www.perl.org/';
exit unless my $html = get $url;
print $html;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 16 Jul 2006 21:38:51 +0200
From: Lars Madsen <daleif@imf.au.dk>
Subject: simulate user activity
Message-Id: <44ba93f7$0$22914$ba624c82@nntp02.dk.telia.net>
I have a new user/server Linux setup that I would like to test using our
diskless terminals (LTSP).
I was thinks about running several test user accounts (to also see how
it behaves with a lot of X activity), and then create a program to be
run by each test user that simulates some normal user behavior.
Something like opening a program from some list, and closing it again
after a while.
But it should of course not run linear, some randomized stuff is of
course needed.
Does anyone have any experience in this area? Does there exist modules
that would help?
Any advise on how to proceed would be appreciated.
/daleif
------------------------------
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 V10 Issue 9483
***************************************