[28406] in Perl-Users-Digest
Perl-Users Digest, Issue: 9770 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 26 11:05:43 2006
Date: Tue, 26 Sep 2006 08:05:06 -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 Tue, 26 Sep 2006 Volume: 10 Number: 9770
Today's topics:
Re: An interactive interpreter/shell? <bik.mido@tiscalinet.it>
drive externally a tcl interpreter <filippo2991@virgilio.it>
Re: list vs. array <uri@stemsystems.com>
Re: list vs. array <tadmc@augustmail.com>
meaning of "child processes are reaped" <bew_ba@gmx.net>
Re: passing multiple values into an argument as an arra <zen13097@zen.co.uk>
Re: passing multiple values into an argument as an arra <bik.mido@tiscalinet.it>
Re: Post to https using perl script <zentara@highstream.net>
Reading from standard input <harpreet.saluja@gmail.com>
Re: Reference to hash value <tadmc@augustmail.com>
Re: Reference to hash value <bik.mido@tiscalinet.it>
regular expression pb. with tags steeve_dun@SoftHome.net
Re: regular expression pb. with tags <David.Squire@no.spam.from.here.au>
Re: regular expression pb. with tags anno4000@radom.zrz.tu-berlin.de
Re: sort with Perl .. <tadmc@augustmail.com>
Re: Splitting and keeping key/value <hjp-usenet2@hjp.at>
Re: Splitting and keeping key/value <mr@sandman.net>
Re: Splitting and keeping key/value <mr@sandman.net>
Re: Splitting and keeping key/value anno4000@radom.zrz.tu-berlin.de
Re: Splitting and keeping key/value <mritty@gmail.com>
Re: Splitting and keeping key/value <mritty@gmail.com>
Re: Splitting and keeping key/value (reading news)
Re: submatch scoping in while <bik.mido@tiscalinet.it>
WIn32API and keyboard <mbw@vp.pl>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 26 Sep 2006 16:27:54 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: An interactive interpreter/shell?
Message-Id: <7edih2tggi2rmnerk0v539na01oio308la@4ax.com>
On 25 Sep 2006 17:01:50 -0700, "robb@acm.org" <robb@acm.org> wrote:
>> >Is there a shell out there that has functionality like Python's
>> >interactive interpreter? I've seen references to a few things out
>>
>> Yes, but it has a strange name. It's called
>>
>> perl -de42
>
>Cute response, but OT.
Is it? I see that you mention yourself psh and others pointed you to
perl-{based,oriented} *command* shells, but since you talked about
"Python's interactive interpreter" I thought that the closest thing
would have been an... interactive Perl interpreter, which is what I
pointed you to. If you do not find that satisfying, care to say why?
$ perl -de42
Loading DB routines from perl5db.pl version 1.28
Editor support available.
Enter h or `h h' for help, or `man perldebug' for more help.
main::(-e:1): 42
DB<1> print "Hello world\n"
Hello world
DB<2> my $x=2;
DB<3> my $y=3;
DB<4> my $z=$x+$y;
DB<5> exit; # I'm tired
Debugged program terminated. Use q to quit or R to restart,
use O inhibit_exit to avoid stopping after program termination,
h q, h R or h O to get additional info.
DB<6> q
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: 26 Sep 2006 06:39:41 -0700
From: "Filippo" <filippo2991@virgilio.it>
Subject: drive externally a tcl interpreter
Message-Id: <1159277981.480878.117190@h48g2000cwc.googlegroups.com>
Hello,
I have a simulation tool (cadence) with TCL interpreter embedded to
control the simulation. Is it possible to write a Perl script that
control the TCL interpreter? I want to write commands to tcl
interpreter in order to be able to control the simulation with an
external Perl program.
Thanks,
Filippo
------------------------------
Date: Tue, 26 Sep 2006 09:56:51 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: list vs. array
Message-Id: <x7odt2viho.fsf@mail.sysarch.com>
>>>>> "d" == dufus <vaginal.infection@gmail.com> writes:
d> robb@acm.org wrote:
>> Uri Guttman wrote:
>>
>> > did you even read the differences i listed?
>>
>> Of course. No reason to get rude.
d> Oh there's every reason to be rude. This is Uri "Motherfucker"
d> Guttman. He is the supreme asshole of this group. To be fair to
d> the bastard, I have to admit he has every reason to be bitter - I
how kind and sweet of you to reply. anonymous posts are so honest and
heartwarming. and your perl skills are renowned throughout the land
too. and such poetry and prose you have composed over the centuries. you
are so famous and yet you deign to write to me personally. i am honored.
and there are cures for vaginal infections. you don't have to be a
recluse anymore. just see a doctor, preferably a headshrinker.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Tue, 26 Sep 2006 08:34:35 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: list vs. array
Message-Id: <slrnehib3b.8in.tadmc@magna.augustmail.com>
robb@acm.org <robb@acm.org> wrote:
> Is it advisable to think about these issues and consider them when
> actually doing programming?
Yes. Much of the time perl's DWIMer will shield you from needing
to know the difference.
But having to qualify it with "Much" implies that some times the
distinction is important.
A rather contrived example:
-----------------------------
#!/usr/bin/perl
use warnings;
use strict;
my $numList = nums_list();
print "list: $numList\n";
my $numArray = nums_array();
print "array: $numArray\n";
sub nums_list { return 4, 5, 6 }
sub nums_array {my @nums=(4, 5, 6); return @nums}
-----------------------------
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 26 Sep 2006 08:00:31 -0700
From: "bernd" <bew_ba@gmx.net>
Subject: meaning of "child processes are reaped"
Message-Id: <1159282830.855214.74170@i42g2000cwa.googlegroups.com>
Hello folks,
not very experienced with interprocess communication and not a native
English speaker I would like to know what the meaning of the expression
"child processes are reaped" is. I encountered it in connection with
Perl's waitpid-function.
Could somebody explain this term?
Cheers
Bernd
------------------------------
Date: 26 Sep 2006 14:12:18 GMT
From: Dave Weaver <zen13097@zen.co.uk>
Subject: Re: passing multiple values into an argument as an array ?
Message-Id: <45193542$0$11783$db0fefd9@news.zen.co.uk>
On 22 Sep 2006 20:43:51 -0700, Jack <jack_posemsky@yahoo.com> wrote:
> I am reading in arguments just fine using the code below, but I want to
> be able to add a variable number of values into an argument into perl -
>
> I want to be able to say
> perl -f value1 value2 ..valueN -v value value2 ..valueN
>
> and store the values of -f in a single array, and -v also (and the
> number of passed values could vary !)
I've just discovered the clever Getopt::Declare module, which can do
just that:
#/usr/bin/perl
use strict;
use warnings;
use Getopt::Declare;
my $args = Getopt::Declare->new(<<END);
-f <value>... a list of values
-v <value>... another list of values
END
my @f = @{ $args->{'-f'} };
my @v = @{ $args->{'-v'} };
print "f = @f, v = @v\n";
------------------------------
Date: 26 Sep 2006 16:27:55 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: passing multiple values into an argument as an array ?
Message-Id: <f0eih2djk5nssinbvgeulm1icjo747hsjp@4ax.com>
On Mon, 25 Sep 2006 12:24:41 -0700, Jim Gibson
<jgibson@mail.arc.nasa.gov> wrote:
>> >I want to be able to say
>> >perl -f value1 value2 ..valueN -v value value2 ..valueN
[snip]
>> You DON'T want that. You want
>>
>> perl yourscript -f whatever -v whatever
^^^^^^^^^^
^^^^^^^^^^
>> Just use Getopt::* and invent a sensible "format" for whatever, i.e.
>> comma separated or value separated, and then parse whatever
>> accordingly, i.e. just split() it.
>
>I am not sure why you advise against wanting multiple values for an
>argument. I have several programs where this feature is quite handy.
Am I advising *against* wanting multiple values for an argument? How
so?
>In any case, multiple values are supported by Getopt::Long if you are
>willing to use multiple entries:
>
> prog -f value1 -f value2
That's another option, but doesn't seem what the OP longs for.
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: Tue, 26 Sep 2006 13:59:31 GMT
From: zentara <zentara@highstream.net>
Subject: Re: Post to https using perl script
Message-Id: <occih29bc8lmjt34v066assm84gnilaut5@4ax.com>
On 25 Sep 2006 13:28:32 -0700, "cardsharper" <Giridhar.Bandi@gmail.com>
wrote:
>Hi
>
>I wanted to post / upload a file to one of our https server
>
>what i am trying to do here is trying to loging to the
>https server using the user credentials . then trying to
>post a file to another url which in general accepts post
>after loging in .
>
>i was able to successfully login, but unable to post
>is this something todo with cookies ?
>
>the error its throughing is "302 Found"
I don't think it has anything to do with cookies. When
you do a post, you need to setup a request object first.
The login and post can all be done in one step.
Try this, it works for me.
#!/usr/bin/perl
use warnings;
use strict;
use LWP::UserAgent;
use HTTP::Cookies;
use HTTP::Request::Common qw(POST);
my $https_url = 'https://192.168.0.1/cgi-bin/uploads/up1.cgi';
my $https_user = 'xxxxx';
my $https_pass = 'yyyyy';
my $file = 'testout.tgz';
&postHTTPS();
sub postHTTPS
{
my $ua = new LWP::UserAgent;
$ua->protocols_allowed( [ 'https'] );
$ua->cookie_jar(HTTP::Cookies->new(file
=>".cookies.txt",autosave => 1));
#setup request
my $req = POST($https_url,
Content_Type => 'multipart/form-data',
Content =>[
file =>[ $file ],
], );
#setup auth
$req->authorization_basic($https_user, $https_pass);
#do post
my $response = $ua->request($req);
if ($response->is_error())
{
printf " %s\n", $response->status_line;
print "https request error!\n";
} else {
my $content = $response->content();
print "$content\n";
}
if ( $response->is_success ) {
print $response->as_string;
}else {
print $response->status_line;
}
}
__END__
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
------------------------------
Date: 26 Sep 2006 07:01:57 -0700
From: "Harpreet" <harpreet.saluja@gmail.com>
Subject: Reading from standard input
Message-Id: <1159279316.691568.149660@k70g2000cwa.googlegroups.com>
Hi.
I am learning perl scripting and was reading an online tutorial where i
encountered this code(at the end of message). The first part of the
code (reading from file) has been pasted as-is and the second(reading
from standard input stream) was written by me. When I execute the
program, I get the correct result from the first one and then I type
into the stream some data but I don't know how to end it. I used the
conventional unix "dot-enter" scheme but it didn't work. Neither did
Ctrl-D. I found some examples which read from <STDIN> and worked with a
while loop. Can somebody explain me why reading from the standard input
doesn't work the way I have written ? If I am missing the escape
character to denote the end of stream, please mention it.
Any pointers will be appreciated.
Thanks and Regards,
Harpreet.
<CODE>
#!usr/local/bin/perl
#
$file = '/etc/passwd'; # Name the file
open(INFO, $file); # Open the file
@lines = <INFO>; # Read it into an array
close(INFO); # Close the file
print @lines; # Print the array
open(INFO, '-');
@lines2 = <INFO>; # Read it into an array
close(INFO);
print @lines2;
</CODE>
------------------------------
Date: Tue, 26 Sep 2006 09:15:56 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Reference to hash value
Message-Id: <slrnehidgs.8in.tadmc@magna.augustmail.com>
schwarzenschafe@gmail.com <schwarzenschafe@gmail.com> wrote:
> What's a better way to write the following:
>
> %hash = %{$hashref1->{"key"}};
> $hashref2 = \%hash;
>
> Assuming $hashref1->{"key"} is a hashref I want to copy (not
> reference), and %hash is never used.
You can use an "anonymous hash constructor" instead of the %hash
temporary variable.
(I think. Can't give a real answer due to lack of real data...)
> My best guess is:
>
> $hashref2 = \%{$hashref1->{"key"}};
>
> But that references $hashref1->{"key"} rather than copies it (ie doesnt
> work).
my $hashref2 = { %{$hashref1->{"key"}} };
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 26 Sep 2006 16:27:57 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Reference to hash value
Message-Id: <c15ih2lsev2ba273cbi3rdqikcecel7u1p@4ax.com>
On 26 Sep 2006 00:43:51 -0700, schwarzenschafe@gmail.com wrote:
>Assuming $hashref1->{"key"} is a hashref I want to copy (not
>reference), and %hash is never used. My best guess is:
>
>$hashref2 = \%{$hashref1->{"key"}};
No. Dereference and reference inverse functions. If you compose them
you obtain identity. I think you want
$hashref2 = { %{$hashref1->{"key"}} };
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: 26 Sep 2006 06:21:01 -0700
From: steeve_dun@SoftHome.net
Subject: regular expression pb. with tags
Message-Id: <1159276860.798580.101160@i42g2000cwa.googlegroups.com>
Hi,
I want to make some pattern replacement. ie to delete every thing
that's between 2 tags.
For example for
1<tag> 2</tag>3
x<tag> a<tag> b </tag> c</tag>z
I want to get
1 3
x z
But I have a problem with embeded tags.
I've tried :
$text =~ s/\<tag\>(.*?)\<\/tag\>//sg;
but it doens't work for embeded tags. It gives:
13
x c</tag>z
Is there a way to deal with this?
Thank you
-steeve
------------------------------
Date: Tue, 26 Sep 2006 14:23:23 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: regular expression pb. with tags
Message-Id: <efb9kb$ed3$1@gemini.csx.cam.ac.uk>
steeve_dun@SoftHome.net wrote:
> Hi,
> I want to make some pattern replacement. ie to delete every thing
> that's between 2 tags.
> For example for
>
> 1<tag> 2</tag>3
> x<tag> a<tag> b </tag> c</tag>z
>
> I want to get
>
> 1 3
> x z
>
> But I have a problem with embeded tags.
> I've tried :
> $text =~ s/\<tag\>(.*?)\<\/tag\>//sg;
> but it doens't work for embeded tags. It gives:
> 13
> x c</tag>z
>
> Is there a way to deal with this?
Yep. Don't try to use regular expressions to parse XML. Use a module
that understands XML. Go to CPAN and you will find many.
DS
------------------------------
Date: 26 Sep 2006 13:24:36 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: regular expression pb. with tags
Message-Id: <4nso0kFbr2v0U1@news.dfncis.de>
<steeve_dun@SoftHome.net> wrote in comp.lang.perl.misc:
> Hi,
> I want to make some pattern replacement. ie to delete every thing
> that's between 2 tags.
> For example for
>
> 1<tag> 2</tag>3
> x<tag> a<tag> b </tag> c</tag>z
>
> I want to get
>
> 1 3
> x z
>
> But I have a problem with embeded tags.
> I've tried :
> $text =~ s/\<tag\>(.*?)\<\/tag\>//sg;
> but it doens't work for embeded tags. It gives:
> 13
> x c</tag>z
>
> Is there a way to deal with this?
Not using regular expressions directly. Use one of the HTML-parsing
modules from CPAN.
Anno
------------------------------
Date: Tue, 26 Sep 2006 08:36:32 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: sort with Perl ..
Message-Id: <slrnehib70.8in.tadmc@magna.augustmail.com>
Mumia W. (reading news) <paduille.4058.mumia.w@earthlink.net> wrote:
> You may safely
> killfile "mumia.w";
Thank you for that useful information!
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 26 Sep 2006 15:27:59 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Splitting and keeping key/value
Message-Id: <slrnehiamv.800.hjp-usenet2@yoyo.hjp.at>
On 2006-09-26 12:21, Paul Lalli <mritty@gmail.com> wrote:
> Sandman wrote:
>> In article <1159267729.600837.37420@m7g2000cwm.googlegroups.com>,
>> "Paul Lalli" <mritty@gmail.com> wrote:
>> > Sandman wrote:
>> > > Indata:
>> > > -------------------------------------
>> > > Date: 2006-04-03
>> > > Message: Wonderful! Let's
>> > > meet there! I'll call you
>> > > later
>> > > Sent by: John
>> > > -------------------------------------
>> >
>> > Please speak Perl, not some bizarre pseudo-code. Do you mean:
>> > my $Indata = "Date: 2006-04-03
>> > Message: Wonderful! Let's
>> > meet there! I'll call you
>> > later
>> > Sent by: John";
>> >
>> > or do you mean:
>> > my @Indata = (
>> > "Date: 2006-04-03\n",
>> > "Message: Wonderful! Let's\n",
>> > "meet there! I'll call you\n",
>> > "later\n",
>> > "Sent by: John\n"
>> > );
>> >
>> > ?
>> >
>> > The difference is important.
>>
>> My indata is a textfile. Sorry.
>
> That completely fails to answer the question. How are you storing this
> data *within your program*.
There is no reason why that data should be stored within the program at
all. The file can be read line by line and the array/hash/whatever
datastructure can be constructed on the fly. Slurping the whole file
into memory may make constructing the desired data structure easier
(hard to tell from the vague descriptions Sandman gave us), but it is
certainly not required.
hp
--
_ | Peter J. Holzer | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR | > ist?
| | | hjp@hjp.at | Was sonst wäre der Sinn des Erfindens?
__/ | http://www.hjp.at/ | -- P. Einstein u. V. Gringmuth in desd
------------------------------
Date: Tue, 26 Sep 2006 15:56:00 +0200
From: Sandman <mr@sandman.net>
Subject: Re: Splitting and keeping key/value
Message-Id: <mr-545DCC.15560026092006@individual.net>
In article <1159273292.373250.51450@b28g2000cwb.googlegroups.com>,
"Paul Lalli" <mritty@gmail.com> wrote:
> > My indata is a textfile. Sorry.
>
> That completely fails to answer the question. How are you storing this
> data *within your program*.
If you don't want to help, that's fine. No need to be aggressive. The
way it's stored within the program isn't important. If you assume it's
stored as the content of a variable, work with that. If you don't want
to make any assumptions, don't hit the reply button.
I've been in this group for way too long to be bothered with people
that rather nitpick on syntax than actually trying to help. For
instance, a good response from you would have been something along the
lines of:
Well, if you have the above in, for example, $data, then I would
probably do something like <code>
And my reply them might have been
Thanks, it's not a variable, but read from STDIN, but I can adapt
' your solution to my indata, thanks for helping me out!
Thanks for listening.
--
Sandman[.net]
------------------------------
Date: Tue, 26 Sep 2006 15:57:27 +0200
From: Sandman <mr@sandman.net>
Subject: Re: Splitting and keeping key/value
Message-Id: <mr-76AD5E.15572726092006@individual.net>
In article <3h9Sg.6492$UG4.1495@newsread2.news.pas.earthlink.net>,
"Mumia W. (reading news)" <paduille.4058.mumia.w@earthlink.net>
wrote:
> I would use the substitution operator s/// to repeatedly suck off
> keyword and value segments and place them in a hash. The /e option to
> s/// allows you execute complicated expressions, and that's what I would
> use here.
>
> Try it yourself.
Yeah, that's pretty much how I've been doing it. I just thought that
there were a more modular approach. I'll try some more. Thanks :)
--
Sandman[.net]
------------------------------
Date: 26 Sep 2006 14:03:59 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Splitting and keeping key/value
Message-Id: <4nsqafFbtkmtU1@news.dfncis.de>
Sandman <mr@sandman.net> wrote in comp.lang.perl.misc:
> In article <3h9Sg.6492$UG4.1495@newsread2.news.pas.earthlink.net>,
> "Mumia W. (reading news)" <paduille.4058.mumia.w@earthlink.net>
> wrote:
>
> > I would use the substitution operator s/// to repeatedly suck off
> > keyword and value segments and place them in a hash. The /e option to
> > s/// allows you execute complicated expressions, and that's what I would
> > use here.
> >
> > Try it yourself.
>
> Yeah, that's pretty much how I've been doing it. I just thought that
> there were a more modular approach. I'll try some more. Thanks :)
You've said that twice now. "Modular" means consisting of independent
components. How does that apply here?
Anno
------------------------------
Date: 26 Sep 2006 07:22:49 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Splitting and keeping key/value
Message-Id: <1159280569.894960.270420@m73g2000cwd.googlegroups.com>
Sandman wrote:
> In article <1159273292.373250.51450@b28g2000cwb.googlegroups.com>,
> "Paul Lalli" <mritty@gmail.com> wrote:
>
> > > My indata is a textfile. Sorry.
> >
> > That completely fails to answer the question. How are you storing this
> > data *within your program*.
>
> If you don't want to help, that's fine. No need to be aggressive.
While I was not being agressive, I rather disagree that there was no
need to be. For some reason, you seem completely unwilling to help
anyone to help you without mulitple prodding.
> The
> way it's stored within the program isn't important
Of course it is. If it's stored in a scalar variable, there are
certain operations you can do on it. If it's stored as a list of
lines, there are other options you can do on it. How is that not
relevant?
>. If you assume it's
> stored as the content of a variable, work with that. If you don't want
> to make any assumptions, don't hit the reply button.
My point is that there is NO REASON to make any assumptions, neither on
my part nor on yours. You clearly are reading the file at some point
in your current script, so why not just tell us *how* you're doing so?!
> I've been in this group for way too long to be bothered with people
> that rather nitpick on syntax than actually trying to help.
I was trying to help. I was trying to help you see how to ask a
question that would be likely to produce a response that would solve
your problem. How is that not helpful?
> For
> instance, a good response from you would have been something along the
> lines of:
>
> Well, if you have the above in, for example, $data, then I would
> probably do something like <code>
No, that would be a REALLY REALLY bad response, because it would
encourage you to continue to post badly formed questions with no
attempt to solve the problem on your own, and would only increase the
number of people who refuse to help you. That would NOT help you in
the long run at all.
Paul Lalli
------------------------------
Date: 26 Sep 2006 07:24:49 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Splitting and keeping key/value
Message-Id: <1159280689.682978.80970@h48g2000cwc.googlegroups.com>
Peter J. Holzer wrote:
> On 2006-09-26 12:21, Paul Lalli <mritty@gmail.com> wrote:
> > Sandman wrote:
> >> In article <1159267729.600837.37420@m7g2000cwm.googlegroups.com>,
> >> "Paul Lalli" <mritty@gmail.com> wrote:
> >> > Sandman wrote:
> >> > > Indata:
> >> > > -------------------------------------
> >> > > Date: 2006-04-03
> >> > > Message: Wonderful! Let's
> >> > > meet there! I'll call you
> >> > > later
> >> > > Sent by: John
> >> My indata is a textfile. Sorry.
> >
> > That completely fails to answer the question. How are you storing this
> > data *within your program*.
>
> There is no reason why that data should be stored within the program at
> all. The file can be read line by line and the array/hash/whatever
> datastructure can be constructed on the fly. Slurping the whole file
> into memory may make constructing the desired data structure easier
> (hard to tell from the vague descriptions Sandman gave us), but it is
> certainly not required.
I was working on the assumption that the text file really is just 5
lines as the OP showed. In that case, the "penalty" for slurping the
entire file is less than negligable, and the benefits of not having to
parse each line looking for the end of the record, storing the previous
line, joining multiple lines to complete the record, etc, are far more
than worth it.
Paul Lalli
------------------------------
Date: Tue, 26 Sep 2006 14:40:19 GMT
From: "Mumia W. (reading news)" <paduille.4058.mumia.w@earthlink.net>
Subject: Re: Splitting and keeping key/value
Message-Id: <nZaSg.6535$UG4.4998@newsread2.news.pas.earthlink.net>
On 09/26/2006 07:44 AM, Mumia W. (reading news) wrote:
> On 09/26/2006 05:29 AM, Sandman wrote:
>> Indata:
>> -------------------------------------
>> Date: 2006-04-03
>> Message: Wonderful! Let's
>> meet there! I'll call you
>> later
>> Sent by: John
>> -------------------------------------
>>
>> I want this parsed into:
>>
>> Array (
>> [Date] => "2006-04-03",
>> [Message] => "Wonderful! Let's\nmeet there! ....."
>> [Sent by] => "John"
>> )
>>
>> By defining keywords that data should be split in, in this case
>> "Date", "Message", "Sent by" and that those should be the first word
>> on the line and they should be followed by a ":". The Message part in
>> my actual indata is at no risk of containing any of these keywords.
>>
>> Any cute ideas on how to solve that? Thanks in advance. :)
>>
>>
>
> I would use the substitution operator s/// to repeatedly suck off
> keyword and value segments and place them in a hash. The /e option to
> s/// allows you execute complicated expressions, and that's what I would
> use here.
>
> Try it yourself.
>
>
S/// is not needed for this. The match operator m// will do just fine
(with lookahead). Read "perldoc perlre" and the section on "Extended
Patterns."
--
paduille.4058.mumia.w@earthlink.net
------------------------------
Date: 26 Sep 2006 16:27:56 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: submatch scoping in while
Message-Id: <6hdih2ttu7e3ntk7aehbdgb99fdl9f3v2a@4ax.com>
On 25 Sep 2006 19:22:00 GMT, anno4000@radom.zrz.tu-berlin.de wrote:
>That doesn't change the behavior. Now catch the match:
>
> while ( ! ( ( $capt) = $x[$i] =~ /^(.)b/) && $i <= $#x ) { $i++ }
> print "\$capt is *$capt*, i is $i\n";
[snip]
>Check the index first.
>
> while ( $i <= $#x && ! ( ( $capt) = $x[$i] =~ /^(.)b/)) { $i++ }
Whatever, I understand that the OP's focus was on an unexpected
behaviour -which generated an interesting discussion- rather on the
actual technique, but AIUI all this is about getting the first element
of an array that matches something, in which case a canonical C<for>
loop (either around 0..$#x or @x depending on whether the index was
really needed or not) with a C<last> would have been just fine.
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: Tue, 26 Sep 2006 15:42:16 +0200
From: "mw" <mbw@vp.pl>
Subject: WIn32API and keyboard
Message-Id: <efbam2$t17$1@news.onet.pl>
Hi !
I test GetAsyncKeyState function on my XP.
Here is my code :
use Win32::API;
my $rsGetAsyncKeyState = new Win32::API("user32", "GetAsyncKeyState", "N",
"I");
sub GetAsyncKeyState {
my ($keyCode) = @_;
my $ret = $rsGetAsyncKeyState->Call($keyCode);
print "ret = $ret\n";
return( $ret & 1 );
}
while () {
sleep 1 ;
$keystate=GetAsyncKeyState(97) ;
# 97 is "a" ascii code
#print "a state=$keystate\n" ; ;
}
When I run this code and press "a" key I see only :
.
.
ret = 0
ret = 0
ret = 0
.
.
.
It means that "a" key is not pressed.
What's wrong ?
Pls help
------------------------------
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 9770
***************************************