[22701] in Perl-Users-Digest
Perl-Users Digest, Issue: 4922 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 1 18:06:18 2003
Date: Thu, 1 May 2003 15:05: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 Thu, 1 May 2003 Volume: 10 Number: 4922
Today's topics:
Creating pop accounts via perl scripts (Zaphod)
Re: Creating pop accounts via perl scripts <nobull@mail.com>
Re: Elegant test for A in B OR B in A? <usenet@tinita.de>
Re: Elegant test for A in B OR B in A? <uri@stemsystems.com>
Re: Equivalent for ksh select? <gregg.dameron@lmco.com>
Re: Executing a MySQL dump file from within a perl scri <mbudash@sonic.net>
Re: Executing a MySQL dump file from within a perl scri <abuse@mweb.co.za>
Re: Executing a MySQL dump file from within a perl scri <mbudash@sonic.net>
Re: how to disable Lingua::EN::NameParse print to stdou <bing-du@tamu.edu>
Net::FTP command <rrunner@san.rr.com>
Re: Net::FTP command <glex_nospam@qwest.net>
Re: perl, grep and multidimensional array - help needed <Rainer.Scherg@t-online.de>
Problem serving binary files <spamsucks@noemail.com>
regex with /\G .. /gc <foobear@nospam.zoom.net>
Re: regex with /\G .. /gc <skuo@mtwhitney.nsc.com>
Re: regex with /\G .. /gc (Malcolm Dew-Jones)
Sending output to 2 frames? <shah@typhoon.xnet.com>
Re: Sending output to 2 frames? <emschwar@pobox.com>
Re: Sending output to 2 frames? <me@privacy.net>
sockets, sysread <meurkens_no@spam_sci.kun.nl>
Re: sockets, sysread <nobull@mail.com>
Re: waste of time <bobx@linuxmail.org>
Re: waste of time (trwww)
Re: waste of time <zentara@highstream.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 1 May 2003 11:59:42 -0700
From: zaphod@earthling.net (Zaphod)
Subject: Creating pop accounts via perl scripts
Message-Id: <fabcf423.0305011059.469322c5@posting.google.com>
I have a database driven web site which users are paying members of..
I am already sending emails via my scripts to members and I also have
administration pages poping the mail box and processing some incomming
mail with Mail::Pop3client...
I have looked around the cpan module list, and if it is there I missed
it, but I would like to provide users that sign up to my service with
a ThierName@MyDomain.com eMail address. I would prefer not to have to
use the control panel my host provides and do each one manually.
Is there a module (which my host will install, they are good about
that) that I can use to automate this process?
------------------------------
Date: 01 May 2003 20:26:06 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Creating pop accounts via perl scripts
Message-Id: <u9issu79kh.fsf@wcl-l.bham.ac.uk>
zaphod@earthling.net (Zaphod) writes:
> I have a database driven web site which users are paying members of..
>
> I am already sending emails via my scripts to members and I also have
> administration pages poping the mail box and processing some incomming
> mail with Mail::Pop3client...
>
> I have looked around the cpan module list, and if it is there I missed
> it, but I would like to provide users that sign up to my service with
> a ThierName@MyDomain.com eMail address. I would prefer not to have to
> use the control panel my host provides and do each one manually.
>
> Is there a module (which my host will install, they are good about
> that) that I can use to automate this process?
Creating accounts on an MTA is a feature of that MTA. If the MTA is
database driven then creating mailboxes may be as simple as an SQL
INSERT (using DBI and the appropriate DBD).
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 1 May 2003 18:06:49 GMT
From: Tina Mueller <usenet@tinita.de>
Subject: Re: Elegant test for A in B OR B in A?
Message-Id: <b8rnnp$d4ccs$1@ID-24002.news.dfncis.de>
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> Tina Mueller <usenet@tinita.de> wrote in comp.lang.perl.misc:
>>
>> print unless index($x,$_) && index ($_,$x)
[...]
> Just a pity it's a little hard to read. It's amazing what a single
> negation can do to obfuscate logic.
yep, i agree to that. (but hey, don't we all know Morgan's
Transform(?) by heart? ;-)
i wasn't sure if i should post it without a comment but
then again i liked it so much... =)
but in a script it should be commented anyway, because if
i look at it tomorrow i probably would have to think about
why it works again myself.
regards, tina
--
http://www.tinita.de/ \ enter__| |__the___ _ _ ___
http://Movies.tinita.de/ \ / _` / _ \/ _ \ '_(_-< of
http://www.perlquotes.de/ \ \ _,_\ __/\ __/_| /__/ perception
http://www.tinita.de/peace/link.html - Spread Peace
------------------------------
Date: Thu, 01 May 2003 19:57:27 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Elegant test for A in B OR B in A?
Message-Id: <x7brym1luh.fsf@mail.sysarch.com>
>>>>> "TM" == Tina Mueller <usenet@tinita.de> writes:
TM> yep, i agree to that. (but hey, don't we all know Morgan's
TM> Transform(?) by heart? ;-) i wasn't sure if i should post it
de Morgan's theorem
A and B same as !A or !B
you just invert both args and flip and/or
basic stuff all programmers must know.
and using unless is generally easier to read than if( !blah )
but in some cases with complex logic and negations, if is better.
i always use unless for simple negated cases.
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: Thu, 1 May 2003 12:03:41 -0600
From: "Gregg Dameron" <gregg.dameron@lmco.com>
Subject: Re: Equivalent for ksh select?
Message-Id: <b8rnht$g021@cui1.lmms.lmco.com>
"Simon Oliver" <simon.oliver@nospam.umist.ac.uk> wrote
> I don't know of a module but here is a little sub that should get you
> started - it doesn't handle terminal height, only width.
Thanks very much, Simon - this is great. Width should be sufficient for
what I need.
Speaking of width: I'm hoping to get this tool running on both Solaris
(xterm) and Win2K (in a command prompt window). I know a couple of ways to
get the xterm's width, but I'm clueless in Win2K. How would I determine the
terminal width there? I found Win32::Console in CPAN - is that the best
place to start?
------------------------------
Date: Thu, 01 May 2003 18:00:40 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Executing a MySQL dump file from within a perl script?
Message-Id: <mbudash-161BD3.11004001052003@typhoon.sonic.net>
In article <pan.2003.05.01.17.52.22.144374@mweb.co.za>,
"Nico Coetzee" <abuse@mweb.co.za> wrote:
> On Wed, 30 Apr 2003 19:04:43 -0700, Garam wrote:
>
> > I have an SQL file created by MySQL dump in the from of:
> >
> > -- MySQL dump 8.22
> > --
> > -- Host: localhost Database: database
> > ---------------------------------------------------------
> > -- Server version 3.23.52
> >
> > --
> > -- Table structure for table 'tablename'
> > --
> >
> > CREATE TABLE tablename (
> > ...
> >
> > It contains a bunch of CREATE TABLE statements. Does anyone know how I
> > can execute the statements in this file from within a Perl script
> > (preferably using DBI, not by using the shell)?
>
> From http://www.mysql.com/doc/en/mysqldump.html :
>
> mysqldump --opt database > backup-file.sql
>
>
> You can read this back into MySQL with:
>
> mysql database < backup-file.sql
>
>
> or
>
> mysql -e "source /patch-to-backup/backup-file.sql" database
>
> You can of course call these routines from Perl
true, but the o.p. specifically asked "preferably using DBI, not by
using the shell"...
--
Michael Budash
------------------------------
Date: Thu, 01 May 2003 20:16:45 +0200
From: "Nico Coetzee" <abuse@mweb.co.za>
Subject: Re: Executing a MySQL dump file from within a perl script?
Message-Id: <pan.2003.05.01.18.16.43.693544@mweb.co.za>
Granted - just checking that all has been taken into account...
In DBI, all he has to execute is: "source /path/to/dump.sql"
I have not tried this though - so I wonder if there is a brave soul in
here that has :)
Cheers
On Thu, 01 May 2003 18:00:40 +0000, Michael Budash wrote:
> In article <pan.2003.05.01.17.52.22.144374@mweb.co.za>,
> "Nico Coetzee" <abuse@mweb.co.za> wrote:
>
>> On Wed, 30 Apr 2003 19:04:43 -0700, Garam wrote:
>>
>> > I have an SQL file created by MySQL dump in the from of:
>> >
>> > -- MySQL dump 8.22
>> > --
>> > -- Host: localhost Database: database
>> > ---------------------------------------------------------
>> > -- Server version 3.23.52
>> >
>> > --
>> > -- Table structure for table 'tablename'
>> > --
>> >
>> > CREATE TABLE tablename (
>> > ...
>> >
>> > It contains a bunch of CREATE TABLE statements. Does anyone know how I
>> > can execute the statements in this file from within a Perl script
>> > (preferably using DBI, not by using the shell)?
>>
>> From http://www.mysql.com/doc/en/mysqldump.html :
>>
>> mysqldump --opt database > backup-file.sql
>>
>>
>> You can read this back into MySQL with:
>>
>> mysql database < backup-file.sql
>>
>>
>> or
>>
>> mysql -e "source /patch-to-backup/backup-file.sql" database
>>
>> You can of course call these routines from Perl
>
> true, but the o.p. specifically asked "preferably using DBI, not by
> using the shell"...
--
Nico Coetzee
http://www.itfirms.co.za/
http://za.pm.org/
http://forums.databasejournal.com/
To the systems programmer, users and applications serve only to provide a
test load.
------------------------------
Date: Thu, 01 May 2003 19:29:53 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Executing a MySQL dump file from within a perl script?
Message-Id: <mbudash-2742E6.12295201052003@typhoon.sonic.net>
In article <pan.2003.05.01.18.16.43.693544@mweb.co.za>,
"Nico Coetzee" <abuse@mweb.co.za> wrote:
> On Thu, 01 May 2003 18:00:40 +0000, Michael Budash wrote:
>
> > In article <pan.2003.05.01.17.52.22.144374@mweb.co.za>,
> > "Nico Coetzee" <abuse@mweb.co.za> wrote:
> >
> >> On Wed, 30 Apr 2003 19:04:43 -0700, Garam wrote:
> >>
> >> > I have an SQL file created by MySQL dump in the from of:
> >> >
> >> > -- MySQL dump 8.22
> >> > --
> >> > -- Host: localhost Database: database
> >> > ---------------------------------------------------------
> >> > -- Server version 3.23.52
> >> >
> >> > --
> >> > -- Table structure for table 'tablename'
> >> > --
> >> >
> >> > CREATE TABLE tablename (
> >> > ...
> >> >
> >> > It contains a bunch of CREATE TABLE statements. Does anyone know how I
> >> > can execute the statements in this file from within a Perl script
> >> > (preferably using DBI, not by using the shell)?
> >>
> >> From http://www.mysql.com/doc/en/mysqldump.html :
> >>
> >> mysqldump --opt database > backup-file.sql
> >>
> >>
> >> You can read this back into MySQL with:
> >>
> >> mysql database < backup-file.sql
> >>
> >>
> >> or
> >>
> >> mysql -e "source /patch-to-backup/backup-file.sql" database
> >>
> >> You can of course call these routines from Perl
> >
> > true, but the o.p. specifically asked "preferably using DBI, not by
> > using the shell"...
>
> Granted - just checking that all has been taken into account...
>
> In DBI, all he has to execute is: "source /path/to/dump.sql"
>
> I have not tried this though - so I wonder if there is a brave soul in
> here that has :)
could you please post your responses at the bottom like everyone else?
it's the _generally_ agreed-upon method 'round here. thanks.
i have tried using 'source' via DBI with mysql 3.23.46. the 'source'
command is not recognized as valid sql:
Unable execute query (source /root/create.sql):1064, You have an error
in your SQL syntax near 'source /root/create.sql' at line 1
however, i was able to get a one-table data-included dump to work with
this:
require './dbconnect.cgi';
open (S, "./create.sql") or die;
my $sql;
while (<S>) {
$sql .= $_ unless (/^#/);
}
close (S);
$sql =~ s/\n//g;
doqry($_) foreach (split /;/, $sql);
(the subroutine doqry uses DBI to execute the sql statements.)
hth-
--
Michael Budash
------------------------------
Date: Thu, 01 May 2003 16:00:49 -0500
From: Bing Du Test <bing-du@tamu.edu>
Subject: Re: how to disable Lingua::EN::NameParse print to stdout?
Message-Id: <3EB18B01.63619C2B@tamu.edu>
Thanks Steven. It helps.
Bing
Steven Kuo wrote:
> On Wed, 30 Apr 2003, Bing Du Test wrote:
>
> > This is perl, v5.6.1 built for sun4-solaris.
> > Lingua::EN::NameParse version 1.18.
> >
> > Lingua::EN::NameParse has 'print' in it. It spits the following stuff
> > when the module is called in my script.
> >
> > Assembling with: <blah blah>
> > Name = <Lingua::EN::NameParse=HASH(0x3e5f4)>, input_string = < blah
> > blah>
> >
> > I don't want to modify Lingua::EN::NameParse.pm itself. Anyway to
> > disable the above module outputs?
> >
> > Thanks in advance for any help,
> >
> > Bing
>
> Perhaps you want to temporarily redirect STDOUT (or whichever
> filehandle to which Lingua::EN::NameParse is printing)? I've not
> looked at Lingua::EN::NameParse, but if it's anything like this
> example:
>
> 1 #! /usr/local/bin/perl
> 2
> 3 package Verbose;
> 4 use base qw(Exporter);
> 5 @EXPORT_OK = qw(bar);
> 6
> 7 use strict;
> 8 use warnings;
> 9
> 10 print "foo\n"; # unwanted message
> 11
> 12 sub bar {
> 13 print "bar\n";
> 14 }
> 15
> 16 1;
> 17
>
> Then you can try 'require' (and import) in the BEGIN block, after
> having redirected STDOUT:
>
> 1 #! /usr/local/bin/perl
> 2 use strict;
> 3 use warnings;
> 4
> 5 BEGIN {
> 6 open(SAVEOUT,">&STDOUT")
> 7 or die "Could not backup STDOUT: $!";
> 8 open(STDOUT, ">/dev/null")
> 9 or die "Could not redirect STDOUT: $!";
> 10 require Verbose;
> 11 import Verbose qw(bar);
> 12 open (STDOUT,">&SAVEOUT")
> 13 or die "Could not restore STDOUT: $!";
> 14 close SAVEOUT
> 15 or warn "Could not close extra FILEHANDLE: $!";
> 16 }
> 17
> 18 bar();
>
> --
> Hope this helps,
> Steven
------------------------------
Date: Thu, 01 May 2003 20:47:29 GMT
From: "Danny" <rrunner@san.rr.com>
Subject: Net::FTP command
Message-Id: <BJfsa.27916$Ye6.1746470@twister.socal.rr.com>
How would I send a bye command when writting a perl script with Net::FTP?
The bye command resets the router when I do it using standard ftp. The quit
in the perl script doesn't do it.
Also I am trying to transfer a firmware up to some routers via ftp using
Net::FTP and when I do the commands directly using ftp into the router this
is the command for transferring the file
put filename.bin ras
I try the $ftp->cwd("/ras")
It doesn't put the file in correctly. The file is really extracted into that
directory I believe. Can anyone help?
------------------------------
Date: Thu, 01 May 2003 16:15:28 -0500
From: Jeff D Gleixner <glex_nospam@qwest.net>
Subject: Re: Net::FTP command
Message-Id: <a4gsa.67$tL4.44536@news.uswest.net>
Danny wrote:
> How would I send a bye command when writting a perl script with Net::FTP?
> The bye command resets the router when I do it using standard ftp. The quit
> in the perl script doesn't do it.
$ftp->close(); #????
>
> Also I am trying to transfer a firmware up to some routers via ftp using
> Net::FTP and when I do the commands directly using ftp into the router this
> is the command for transferring the file
>
> put filename.bin ras
That puts the local file 'filename.bin' onto the current working directory
on the remote machine as 'ras'.
man ftp
>
> I try the $ftp->cwd("/ras")
>
> It doesn't put the file in correctly. The file is really extracted into that
> directory I believe. Can anyone help?
$ftp->cwd('to/whereever/you/want/to/be');
$ftp->put('filename.bin', 'ras');
perldoc Net::FTP
------------------------------
Date: Thu, 01 May 2003 22:21:18 +0200
From: Rainer Scherg <Rainer.Scherg@t-online.de>
Subject: Re: perl, grep and multidimensional array - help needed
Message-Id: <3EB181BE.9E81333E@t-online.de>
[shame on]
Well the bug was so simple and braindead, I didn't see it for two
days. Because I'm used to post only essential parts in a message,
I missed one "bad" and simple code line.
@fields = split /\|/, $line; # split ...
if ($fields[1] > $value) {
$list[$count] = [@fields];
}
count++;
^^^^^^^
@list2 = grep { $_->[2] !~ /some-pattern/i } @list;
This ^^^ has to be in the inner part of the if condition,
of course. [ARGHHH - reboot neural network]
Anyway, tnx for helping...
Rainer
Anno Siegel schrieb:
>
> Rainer Scherg <Rainer.Scherg@t-online.de> wrote in comp.lang.perl.misc:
> >
>
> Not normally. However, a forgotten ";" or ")" or similar can lead
> to mis-parsing with the "Modification..." message. Look for that,
> or post complete code that *demonstrates* the problem.
>
> Anno
------------------------------
Date: Thu, 01 May 2003 21:56:24 GMT
From: "Topspin" <spamsucks@noemail.com>
Subject: Problem serving binary files
Message-Id: <_Jgsa.141$6c.46@news.randori.com>
I have the following Perl script runnin on a Unix box with Apache HTTP. It
works perfectly. I changed the top line to get the script to work on a
Windows box and it appears to work, but the the gif image never appears in
the browser. It appears to be incomplete because if I right mouse click on
the center of the page, I can "Save the image" to my hard drive. When I
open the saved image up in a paint program, it shows the correct dimensions
and color pallete, but the image is blank. It's as if the browser is trying
to show the image before it is done being sent. Any ideas why this works
perfectly on Unix but dies on Windows. No errors are generated and both
machines are running Apache.
Thanks.
code...
#! c:\perl\bin\perl
# #!/usr/local/bin/perl - this line used when on the Unix box but remarked
out for the Windows machine.
# Define variables.
$finaldir= "c:/gifs/"; # Location of file to retrieve
$default = "notfound"; # Name of gif to serve if requested gif not found
$param = "url"; # Parameter that contains the file to retrieve
&get_request;
# Get filename of graph to retrieve.
if ($rqpairs{$param} eq "") {
$file = $finaldir.$default; # Default map is displayed if none specified
} else {
$file = $finaldir.$rqpairs{$param};
}
# Serve gif to browser.
open (code, "$file.gif") || die;
print "Content-type: image/gif\n\n";
print <code>;
close (code);
exit;
sub get_request {
if ($ENV{'REQUEST_METHOD'} eq "POST") {
read(STDIN, $request, $ENV{'CONTENT_LENGTH'});
} elsif ($ENV{'REQUEST_METHOD'} eq "GET" ) {
$request = $ENV{'QUERY_STRING'};
}
%rqpairs = ();
@rqarray = split(/[&=]/, $request);
while ( $key = shift(@rqarray) ) {
$value = shift(@rqarray);
if ( $rqpairs{$key} ne "" ) {
$rqpairs{$key} .= "," . $value;
}
else {
$rqpairs{$key} = $value;
}
}
}
------------------------------
Date: Thu, 01 May 2003 19:56:49 GMT
From: <foobear@nospam.zoom.net>
Subject: regex with /\G .. /gc
Message-Id: <5_esa.74$m53.7391@petpeeve.ziplink.net>
Hello folks,
Maybe you can throw me a bone here....
I want to tokenize a string, or process it part by part doing
something different with each piece depending on what regex matched.
After reading perlre and perlop I think I want to use \G with /gc.
The string starts with the 'letter S letter followed by a number'
Then immediately follow key value pairs, in the format
'key: value, key: value, key: value' ...
But _don't_ pick up 'NOTES:' even though it looks like a key
Then follows some junk we can skip (GSL 1)
Then follows NOTES: and more key value pairs in the format
"key" "value, "key "value", "key value", ...
This is what I have so far, It seems to be working but I suspect
I'm getting lucky and maybe using negative lookbehind wrong?
I need to scan many thousands of strings like this very often, so
I thought at using \G would be efficient since I don't have to start
scanning from the beginning of the string again. I must be using
it wrong though because when I add it to the beginning of my regex
I don't match anything. (its ommited in my examples below to show
a working example that outputs what I want).
Is there a more efficient way of doing this perhaps? There is an
example in perldoc perlop that demonstrates what I have in mind,
search for 'lex-like'
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
my %h;
$_ = 'S89 Key: 255.255.255.255:319510, NAS: 1.1.1.1, NAS-Port: 666,
User-Name: foo@bar.baz, Time: 94:35:09, GSL 1,
NOTES: "Acct-Session-Id" "0048939656", "FooNote" "1.2.3.4",
"BarNote" "whee"';
LOOP: {
$h{id} = $1, redo if /^(S\d+)/gc;
$h{$1} = $2, redo if /(\S+)(?<!NOTES):\s([^,\s]+)/gc;
$h{notes}{$1} = $2, redo if /"([^"]+)"\s+"([^"]*)"/gc
}
print Dumper \%h;
__END__
And the ouput it exactly what I want it to be:
$VAR1 = {
'notes' => {
'FooNote' => '1.2.3.4',
'BarNote' => 'whee',
'Acct-Session-Id' => '0048939656'
},
'Key' => '255.255.255.255:319510',
'NAS' => '1.1.1.1',
'NAS-Port' => 666,
'User-Name' => 'foo@bar.baz',
'id' => 'S89',
'Time' => '94:35:09'
};
Thanks for any ideas.
------------------------------
Date: Thu, 1 May 2003 14:41:49 -0700
From: Steven Kuo <skuo@mtwhitney.nsc.com>
Subject: Re: regex with /\G .. /gc
Message-Id: <Pine.GSO.4.21.0305011435200.6592-100000@mtwhitney.nsc.com>
On Thu, 1 May 2003 foobear@nospam.zoom.net wrote:
(snipped) ...
>
> I need to scan many thousands of strings like this very often, so
> I thought at using \G would be efficient since I don't have to start
> scanning from the beginning of the string again. I must be using
> it wrong though because when I add it to the beginning of my regex
> I don't match anything. (its ommited in my examples below to show
> a working example that outputs what I want).
>
> Is there a more efficient way of doing this perhaps? There is an
> example in perldoc perlop that demonstrates what I have in mind,
> search for 'lex-like'
>
>
> #!/usr/bin/perl -w
> use strict;
> use Data::Dumper;
>
> my %h;
> $_ = 'S89 Key: 255.255.255.255:319510, NAS: 1.1.1.1, NAS-Port: 666,
> User-Name: foo@bar.baz, Time: 94:35:09, GSL 1,
> NOTES: "Acct-Session-Id" "0048939656", "FooNote" "1.2.3.4",
> "BarNote" "whee"';
>
> LOOP: {
> $h{id} = $1, redo if /^(S\d+)/gc;
> $h{$1} = $2, redo if /(\S+)(?<!NOTES):\s([^,\s]+)/gc;
> $h{notes}{$1} = $2, redo if /"([^"]+)"\s+"([^"]*)"/gc
> }
>
> print Dumper \%h;
>
> __END__
>
> And the ouput it exactly what I want it to be:
> $VAR1 = {
> 'notes' => {
> 'FooNote' => '1.2.3.4',
> 'BarNote' => 'whee',
> 'Acct-Session-Id' => '0048939656'
> },
> 'Key' => '255.255.255.255:319510',
> 'NAS' => '1.1.1.1',
> 'NAS-Port' => 666,
> 'User-Name' => 'foo@bar.baz',
> 'id' => 'S89',
> 'Time' => '94:35:09'
> };
>
> Thanks for any ideas.
>
#!/usr/local/bin/perl
use Data::Dumper;
my %h;
$_ = 'S89 Key: 255.255.255.255:319510, NAS: 1.1.1.1, NAS-Port: 666,
User-Name: foo@bar.baz, Time: 94:35:09, GSL 1,
NOTES: "Acct-Session-Id" "0048939656", "FooNote" "1.2.3.4",
"BarNote" "whee"';
substr($_,0,0) = 'id: ';
LOOP:
{
# With some extra print statements for debugging thrown in:
$h{$1} = $2, redo LOOP if m#\G(\S+)(?<!NOTES):\s([^,\s]+),?\s+(?{print pos,$/;})#gc;
print "Begin again at ", pos , "\n";
$h{'notes'}{$1} = $2, redo LOOP if m/"([^"]+)"\s+"([^"]*)"/g;
}
# Or even:
my %g;
$g{$1}=$2 while (m/\G(\S+)(?<!NOTES):\s([^,\s]+),?\s+/gc);
print "TIMTOWTDI: begin again at ", pos, "\n";
$g{'notes'}{$1} = $2 while (m/"([^"]+)"\s+"([^"]*)"/gc);
print Dumper \%h, \%g;
--
Hope this helps,
Steven
------------------------------
Date: 1 May 2003 15:00:21 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: regex with /\G .. /gc
Message-Id: <3eb198f5@news.victoria.tc.ca>
foobear@nospam.zoom.net wrote:
: Hello folks,
: Maybe you can throw me a bone here....
: I want to tokenize a string, or process it part by part doing
: something different with each piece depending on what regex matched.
: After reading perlre and perlop I think I want to use \G with /gc.
/g causes the re engine to start looking where it left of last time.
e.g.
m/hello/ starts looking at the start of the string, but the word
hello can be anywhere in the string.
m/hello/g starts looking where it left of last time, but the word
hello can occur anywhere after that point in the string.
\G is an anchor, it works very much like ^ (which forces the match to be
the first thing in a string), except that instead of forcing the match to
be the first thing in the string, it forces the match to be the very next
thing in the string.
e.g.
m/^hello/ starts looking at the start of the string, and the word
hello must be the very first thing it finds.
m/\Ghello/ starts looking where it left of last time, and the word
hello must be the very first thing it finds. (That description may not be
100% correct).
If you say m/\GHello/gc then the H in Hello has to be the very next letter
after the last match.
On the other hand m/\G(.*?)hello/gc would look for hello anywhere after
the last match, and capture everything between the matches. (and the \G
is probably redundant).
------------------------------
Date: Thu, 1 May 2003 20:49:14 +0000 (UTC)
From: Hemant Shah <shah@typhoon.xnet.com>
Subject: Sending output to 2 frames?
Message-Id: <b8s189$6dk$1@flood.xnet.com>
Folks,
I have a html page with 2 frames. When someone clicks on a button
in frame 1 my Javascript function performs some checks and calls a perl
CGI script.
From the perl script if I find some problems I want to send the output to
frame 2 so that the frame 1 does not get wiped out. If everything is
O.K. then I want to redirect frame 1 to another html document.
How can I do that?
+--------------------+
| |
| +--------+ |
| | Button |--- +-----------> +------------------+
| +--------+ | | Perl CGI script |
| | | |
| | | |
| |<------------+- Redirect |
| frame 1 | | |
| | | |
| | | |
| | | |
| | | |
+--------------------+ | |
| | | |
| frame 2 |<------------+- Error |
| | +------------------+
| |
| |
+--------------------+
Thanks.
--
Hemant Shah /"\ ASCII ribbon campaign
E-mail: NoJunkMailshah@xnet.com \ / ---------------------
X against HTML mail
TO REPLY, REMOVE NoJunkMail / \ and postings
FROM MY E-MAIL ADDRESS.
-----------------[DO NOT SEND UNSOLICITED BULK E-MAIL]------------------
I haven't lost my mind, Above opinions are mine only.
it's backed up on tape somewhere. Others can have their own.
------------------------------
Date: 01 May 2003 14:58:19 -0600
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: Sending output to 2 frames?
Message-Id: <eto65ou5qqc.fsf@wormtongue.emschwar>
Hemant Shah <shah@typhoon.xnet.com> writes:
> I have a html page with 2 frames. When someone clicks on a button
> in frame 1 my Javascript function performs some checks and calls a perl
> CGI script.
Let's pretend that CGI script is in COBOL, not Perl. Do you have the
same problems you did before? If so, and I would bet money the answer
is 'yes', then your problem is either CGI-related, in which case
c.i.w.a.cgi might have some answers, or javascript-related, in which
case your Followup-To: of clpm is in error.
> From the perl script if I find some problems I want to send the output to
> frame 2 so that the frame 1 does not get wiped out. If everything is
> O.K. then I want to redirect frame 1 to another html document.
>
> How can I do that?
Probably with Javascript. Followups set.
-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
------------------------------
Date: Thu, 1 May 2003 23:02:14 +0200
From: Norbert Schmidt <me@privacy.net>
Subject: Re: Sending output to 2 frames?
Message-Id: <gf6x69tkdvgk$.ikqaccrfvm4k.dlg@40tude.net>
Hello Hemant,
> I have a html page with 2 frames. When someone clicks on a button
> in frame 1 my Javascript function performs some checks and calls a perl
> CGI script.
> From the perl script if I find some problems I want to send the output to
> frame 2 so that the frame 1 does not get wiped out. If everything is
> O.K. then I want to redirect frame 1 to another html document.
the easiest solution seems to me that you call the script with "frame 2" as
target.
When everything is ok, your script should generate a blank page with just
some Javascript code (OnLoad handler) that reloads "frame 1".
This approach has the additional benefit of clearing the error frame.
Regards, Norbert
------------------------------
Date: Thu, 01 May 2003 21:12:01 +0000
From: Stijn Meurkens <meurkens_no@spam_sci.kun.nl>
Subject: sockets, sysread
Message-Id: <3eb170f0$0$49115$e4fe514c@news.xs4all.nl>
Hello,
I'm catching messages from a socket with sysread, but now it happens
sometimes that multiple messages are stored in one string. How can I
prevent this, or how can I split this string up (splitting up by newlines
doesn't work; newlines can be part of a message).
Thanks already,
Stijn
------------------------------
Date: 01 May 2003 20:27:56 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: sockets, sysread
Message-Id: <u9el3i79hf.fsf@wcl-l.bham.ac.uk>
Stijn Meurkens <meurkens_no@spam_sci.kun.nl> writes:
> I'm catching messages from a socket with sysread, but now it happens
> sometimes that multiple messages are stored in one string. How can I
> prevent this, or how can I split this string up (splitting up by newlines
> doesn't work; newlines can be part of a message).
Do not attempt to treat byte-stream protocols as datagram protocols.
If you do you will get into a mess. This has nothing to do with Perl.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 01 May 2003 21:11:34 GMT
From: "Bob X" <bobx@linuxmail.org>
Subject: Re: waste of time
Message-Id: <a4gsa.6634$hT2.4064992@news2.news.adelphia.net>
"smugbuster" <smugbuster@hotmail.com> wrote in message
news:677cff64.0304300948.7e8878c4@posting.google.com...
> your little newsgroup or whatever you call it is a waste of time for
> anybody trying to learn anything new.
>
> legitimate questions are disparaged, ridiculed, and made fun of.
> what's wrong with you people? you were all newbies once!
>
Really?
Speaking as a newbie I have found a plethora of answers from this group.
Sometime I get a "perldoc this" or "perldoc that" but that is a-okay. I have
learned far more in a short time because of it. Which is probably a reason
they do it.
------------------------------
Date: 1 May 2003 14:11:39 -0700
From: toddrw69@excite.com (trwww)
Subject: Re: waste of time
Message-Id: <d81ecffa.0305011311.959e92@posting.google.com>
smugbuster@hotmail.com (smugbuster) wrote in message news:<677cff64.0304300948.7e8878c4@posting.google.com>...
> your little newsgroup or whatever you call it is a waste of time for
> anybody trying to learn anything new.
>
> legitimate questions are disparaged, ridiculed, and made fun of.
> what's wrong with you people? you were all newbies once!
>
Well, alot of questions that should never get posted to this list do
get posted here.
Beginners should use the perl.beginners news group on the nntp server
nntp.perl.org
Todd W.
------------------------------
Date: Thu, 01 May 2003 17:40:03 -0400
From: zentara <zentara@highstream.net>
Subject: Re: waste of time
Message-Id: <rs43bv4gqhn6r5jimqlduj2rgndudlppgf@4ax.com>
On 30 Apr 2003 10:48:01 -0700, smugbuster@hotmail.com (smugbuster)
wrote:
>your little newsgroup or whatever you call it is a waste of time for
>anybody trying to learn anything new.
>
>legitimate questions are disparaged, ridiculed, and made fun of.
>what's wrong with you people? you were all newbies once!
Well, go to perl newsgroup which is friendlier. This place is like
"the major leagues"; they don't take kindly to asking "which way
do I run the bases?".
Go to nntp.perl.org and subscribe to the perl.beginners newsgroup.
You will find friendly experts who like to help beginners.
You can also find friendly help at http://perlmonks.org
This newsgroup is more for the experts to discuss the finer points of
Perl. Don't get discouraged, the comp.lang.c newsgroup is the same
way, they will answer a few simple questions, then tell you to go read a
book.
------------------------------
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 4922
***************************************