[25158] in Perl-Users-Digest
Perl-Users Digest, Issue: 7407 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 15 21:06:01 2004
Date: Mon, 15 Nov 2004 18:05:05 -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 Mon, 15 Nov 2004 Volume: 10 Number: 7407
Today's topics:
Re: A preference in the style guide <usenet@morrow.me.uk>
Re: DBD::CSV or DBD::DBM or something else? <1usa@llenroc.ude.invalid>
Re: Easiest way to read one character at a time until t <jgibson@mail.arc.nasa.gov>
FAQ 9.9: How do I automate an HTML form submission? <comdog@panix.com>
Far More Than Everything You've Ever Wanted to Know abo (Xavier Noria)
How to read access database file with perl? <tihana@verso.co.izbaciovo>
Re: How to read access database file with perl? <news@general-purpo.se>
Re: How to read access database file with perl? <segraves_f13@mindspring.com>
How to work (?{code}) <admin@asarian-host.net>
Re: How to work (?{code}) <mritty@gmail.com>
Re: How to work (?{code}) <tadmc@augustmail.com>
Re: How to work (?{code}) <admin@asarian-host.net>
Need RegExp <abc@microsoft.com>
Re: Need RegExp <tadmc@augustmail.com>
problems using taint to check an array be created by cg <phill@mywebstuff.com>
Re: problems using taint to check an array be created b <1usa@llenroc.ude.invalid>
RegEx challenge - jrs (John R)
Re: RegEx challenge - jrs <1usa@llenroc.ude.invalid>
Re: replace pattern including newline : perl version 5. (Prince Kumar)
Re: Sending email using perl <jgibson@mail.arc.nasa.gov>
Re: Two operations with one last if? <dwall@fastmail.fm>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 16 Nov 2004 00:08:51 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: A preference in the style guide
Message-Id: <j1tn62-an6.ln1@osiris.mauzo.dyndns.org>
Quoth anno4000@lublin.zrz.tu-berlin.de (Anno Siegel):
> Arndt Jonasson <do-not-use@invalid.net> wrote in comp.lang.perl.misc:
> >
> > I've been reading the style guide (perldoc perlstyle), and I have
> > trouble understanding one of the short preferences listed in the
> > beginning:
> >
> > "Space after last parenthesis matching on current line."
> >
> > Can someone give simple examples where this preference is
> > followed, and not followed, respectively?
>
> This follows the rule:
>
> foo(
> bar( baz( 3.141)) );
>
> There's a space before the last ")" because the matching opening "("
> isn't on the same line.
FWIW I've recently taken to invariably writing the above as
foo(
bar( baz(3.141))
);
with the closing ) lined up as though it was a brace: it uses an extra
line, but I find it much clearer. (to generalize, I would write a
compilcated if as
if (
foo && bar && baz
) {
...
}
.)
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 ben@morrow.me.uk
------------------------------
Date: 15 Nov 2004 19:47:59 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: DBD::CSV or DBD::DBM or something else?
Message-Id: <Xns95A2968D64A55asu1cornelledu@132.236.56.8>
meneg <meneg@nospm.org> wrote in
news:pan.2004.11.15.18.55.37.301280@nospm.org:
> Hello all and thanks in advance for any help you may give.
>
> I'm currently in the process of making a cgi website for a family
> business which would carry a few online orders and a few database
> entries.
Strictly speaking, this is not a Perl question but ...
> I soon came to realize using postgresql - which I used last
> year when I was learning php - would be an overkill because we talk
> about no more that a thousand entries in a couple of small tables.
> Also since our hosting is remote, I don't want to deal with remote
> databases.
Is this shared hosting? If so, and if the database is properly set up, it
would be much more secure to use Postgresql or MySQL.
> Anyway, to the point. I read a a couple of decent perl books in the
> past couple of months and I remember - not exactly where - that
> DBD::CSV is a great alternative to a full featured SQL server or a
> hard to maintain plain flat file.
The user id under which the web server is running will need to be able to
read the CSV files. That means, the whole world would need to be able
toread them. Putting financial information in those files is a sure
recipe for disaster.
Please note that your question is independent of the language you are
programming in.
Sinan.
------------------------------
Date: Mon, 15 Nov 2004 12:14:08 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Easiest way to read one character at a time until the first |
Message-Id: <151120041214086967%jgibson@mail.arc.nasa.gov>
In article <20041114005055.07103.00000524@mb-m10.aol.com>,
Mortgageloan2004 <mortgageloan2004@aol.com> wrote:
> I'd like to grab a line from a file (up to the newline) and then read one
> character of a lin starting at the far left, until I get to the end of the
> first data element in a flat text file, (until first pipe symbol reached)
> counting the number of characters with a counter. Assign the first counter
> -1
> characters to a variable. Then test to see if it matches the string being
> searched. If it does, then grab the third data element. Everything between the
> 2nd and 3rd pipe symbol and end the loop. If it doesn't match, then read in
> the
> next line from the file.
>
> Is this possible? Any ideas are appreciated very much.
#!/usr/local/bin/perl
#
use strict;
use warnings;
my $third; # declare $third outside loop
while( my $line = <DATA> ) {
chomp($line);
my @fields = split('\|',$line); # need to escape pipe here
my $count = length($fields[0]) - 1; # not really necessary
my $variable = $fields[0]; # ditto
if( $variable =~ /search/ ) { # can test $fields[0] here
$third = $fields[2];
last;
}
}
print "third is '$third'\n";
__DATA__
field 1, line 1|field 2, line 1|field 3, line 1
field 1, line 2|field 2, line 2|field 3, line 2
search|field 2, line 3|field 3, line 3
field 1, line 4|field 2, line 4|field 3, line 4
field 1, line 5|field 2, line 5|field 3, line 5
Output:
third is 'field 3, line 3'
See 'perldoc -f open' for reading actual files.
------------------------------
Date: Mon, 15 Nov 2004 23:03:04 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 9.9: How do I automate an HTML form submission?
Message-Id: <cnbcj8$736$1@reader1.panix.com>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.
--------------------------------------------------------------------
9.9: How do I automate an HTML form submission?
If you're submitting values using the GET method, create a URL and
encode the form using the "query_form" method:
use LWP::Simple;
use URI::URL;
my $url = url('http://www.perl.com/cgi-bin/cpan_mod');
$url->query_form(module => 'DB_File', readme => 1);
$content = get($url);
If you're using the POST method, create your own user agent and encode
the content appropriately.
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
$ua = LWP::UserAgent->new();
my $req = POST 'http://www.perl.com/cgi-bin/cpan_mod',
[ module => 'DB_File', readme => 1 ];
$content = $ua->request($req)->as_string;
--------------------------------------------------------------------
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-2002 Tom Christiansen and Nathan
Torkington, and other contributors as noted. All rights
reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
------------------------------
Date: 15 Nov 2004 15:23:59 -0800
From: fxn@hashref.com (Xavier Noria)
Subject: Far More Than Everything You've Ever Wanted to Know about Prototypes in Perl
Message-Id: <31a13074.0411151523.312c140d@posting.google.com>
Is the article "Far More Than Everything You've Ever Wanted to Know
about Prototypes in Perl" yet at perl.com? It was normally available
at
http://www.perl.com/pub/language/misc/fmproto.html
but right now there's no content there. Does it have a new address
maybe? Anyone has a copy at least if not?
-- fxn
------------------------------
Date: Mon, 15 Nov 2004 23:50:38 +0100
From: "Tihana" <tihana@verso.co.izbaciovo>
Subject: How to read access database file with perl?
Message-Id: <419932b1$1@news.s5.net>
How to read access database file with perl?
Is it possible without Microsoft Office instaled on PC?
------------------------------
Date: 15 Nov 2004 17:33:10 -0600
From: David Kroeber <news@general-purpo.se>
Subject: Re: How to read access database file with perl?
Message-Id: <slrncpieva.78p.news@bonn.de.eu.taffy.nl>
* Tihana:
> How to read access database file with perl?
> Is it possible without Microsoft Office instaled on PC?
I didn't find any modules to access .mdb files (jetdb). So
http://mdbtools.sourceforge.net/ might help (at least if you are on a
Unix box). You could use DBD::ODBC too (search for DBI on CPAN), but
actually I don't know if there are Access Drivers for ODBC without
installing Office or Access...
bye
//Dave
--
Ja, der typische "Ich tippe alles ein was mir ein paar Trottel aus dem
IRC sagen"-Newbie wird aber kein Solaris nutzen... ;)
-- Christoph Gebhardt in bjt
------------------------------
Date: Tue, 16 Nov 2004 00:56:36 GMT
From: "Bill Segraves" <segraves_f13@mindspring.com>
Subject: Re: How to read access database file with perl?
Message-Id: <8fcmd.38$pK6.24@newsread2.news.atl.earthlink.net>
"Tihana" <tihana@verso.co.izbaciovo> wrote in message
news:419932b1$1@news.s5.net...
> How to read access database file with perl?
Win32::ODBC
> Is it possible without Microsoft Office instaled on PC?
Yes.
BTW, Google and Google Groups are your friends.
A Google Groups search for the thread "Re: s there a module to acess
Microsoft Access datafiles?" should help you get started. Another search for
"Re: Win32::ODBC to Remote Database (LAN connected) " should get you to some
contributions by Dave Roth, including a link to his web site, re:
Win32::ODBC.
You'll likely have questions that are inappropriate for this newsgroup,
e.g., how to set up a DSN on a Win32 system. Please check the posting
guidelines.
Cheers.
--
Bill Segraves
------------------------------
Date: Mon, 15 Nov 2004 22:06:54 +0100
From: "Mark" <admin@asarian-host.net>
Subject: How to work (?{code})
Message-Id: <RpSdnS_O0LjvhwTcRVn-2A@giganews.com>
I was wondering if someone could explain the proper working of (?{code}) to
me. I tried the following, in Perl 5.8.5:
--------------------------
sub code_test {
my $data = 'something';
return ($data);
}
$search = 'example.com';
if ($search =~ /(?{code_test ()})$/i) {
print "Yes: $search, $^R, $&\n";
}
exit 0;
--------------------------
The problem is, that the if () always returns "true", even if there is no
match against the regex. Obviously, I am misunderstanding something. I hope
someone can tell me what I missed.
Thanks.
- Mark
------------------------------
Date: Mon, 15 Nov 2004 21:20:42 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: How to work (?{code})
Message-Id: <K49md.10035$tI3.3096@trndny01>
"Mark" <admin@asarian-host.net> wrote in message
news:RpSdnS_O0LjvhwTcRVn-2A@giganews.com...
> I was wondering if someone could explain the proper working of
(?{code}) to
> me. I tried the following, in Perl 5.8.5:
>
> --------------------------
> sub code_test {
> my $data = 'something';
> return ($data);
> }
>
> $search = 'example.com';
>
> if ($search =~ /(?{code_test ()})$/i) {
> print "Yes: $search, $^R, $&\n";
> }
>
> exit 0;
> --------------------------
>
> The problem is, that the if () always returns "true", even if there is
no
> match against the regex. Obviously, I am misunderstanding something. I
hope
> someone can tell me what I missed.
Did you try the documentation for the feature you're using?
perldoc perlre:
"(?{ code })"
WARNING: This extended regular expression feature
is considered highly experimental, and may be
changed or deleted without notice.
This zero-width assertion evaluate any embedded
Perl code. It always succeeds, and its "code" is
not interpolated.
In other words, (?{code()}) has no intrinsic effect on your regular
expression. It is *always* true. The result of the code is not
examined by the regexp engine to try to match anything. It's as though
in the middle of your regexp, you tell perl "Wait, hang on, I have to go
do something.... okay, now go ahead where you left off."
Now, on the other hand, the very next entry in perldoc perlre is:
"(??{ code })"
WARNING: This extended regular expression feature
is considered highly experimental, and may be
changed or deleted without notice. A simplified
version of the syntax may be introduced for
commonly used idioms.
This is a "postponed" regular subexpression. The
"code" is evaluated at run time, at the moment
this subexpression may match. The result of
evaluation is considered as a regular expression
and matched as if it were inserted instead of this
construct.
Perhaps that's what you were looking for instead?
Paul Lalli
------------------------------
Date: Mon, 15 Nov 2004 17:04:20 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: How to work (?{code})
Message-Id: <slrncpidfk.1eg.tadmc@magna.augustmail.com>
Mark <admin@asarian-host.net> wrote:
> I was wondering if someone could explain the proper working of (?{code}) to
> me.
perlre.pod does a pretty good job of that I think:
This zero-width assertion evaluate any embedded Perl code. It
always succeeds, and its C<code> is not interpolated.
> if ($search =~ /(?{code_test ()})$/i) {
> The problem is, that the if () always returns "true",
your code is the same as:
if ($search =~ /$/i) {
only without the side-effects of evaluating the call to code_test().
It is *supposed to* always return true.
> even if there is no
> match against the regex.
The empty string matches *every* string.
> Obviously, I am misunderstanding something. I hope
> someone can tell me what I missed.
You are missing a question mark. :-)
You want (?? { code }) rather than (? { code }).
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 16 Nov 2004 01:23:49 +0100
From: "Mark" <admin@asarian-host.net>
Subject: Re: How to work (?{code})
Message-Id: <ididnadyDpAE1QTcRVn-2w@giganews.com>
"Paul Lalli" <mritty@gmail.com> wrote in message
news:K49md.10035$tI3.3096@trndny01...
> Did you try the documentation for the feature you're using?
>
> perldoc perlre:
> "(?{ code })"
> WARNING: This extended regular expression feature
> is considered highly experimental, and may be
> changed or deleted without notice.
>
> This zero-width assertion evaluate any embedded
> Perl code. It always succeeds, and its "code" is
> not interpolated.
>
> In other words, (?{code()}) has no intrinsic effect on your regular
> expression. It is *always* true. The result of the code is not
> examined by the regexp engine to try to match anything.
Yes, I read the docs (some older ActiveState Perl docs, here not at home). I
just focussed on the 'experimental', and figured I was not bothered by that
if it worked.
> It's as though
> in the middle of your regexp, you tell perl "Wait, hang on, I have to go
> do something.... okay, now go ahead where you left off."
>
> Now, on the other hand, the very next entry in perldoc perlre is:
> "(??{ code })"
> WARNING: This extended regular expression feature
> is considered highly experimental, and may be
> changed or deleted without notice. A simplified
> version of the syntax may be introduced for
> commonly used idioms.
>
> This is a "postponed" regular subexpression. The
> "code" is evaluated at run time, at the moment
> this subexpression may match. The result of
> evaluation is considered as a regular expression
> and matched as if it were inserted instead of this
> construct.
>
> Perhaps that's what you were looking for instead?
I missed that. My bad, obviously; my appreciation nonetheless, as this is
exactly what I needed!
Thanks.
- Mark
------------------------------
Date: Mon, 15 Nov 2004 18:32:17 GMT
From: "Indigo5" <abc@microsoft.com>
Subject: Need RegExp
Message-Id: <I78Gts.1ny@news.boeing.com>
I need a way of parsing a variable format. Basically the section starts off
with a Reference keyword and ends with a Comments keyword.
Reference:
1. document1
2 document2
Comments:
I was doing this as follows:
if (/^Reference/ .. /^Comments/){
if (/^[0-9]/){
chomp;
$_ =~ s/^[0-9].\s+//g;
push @references, $_;
}
}
However, I just received a document where Reference 1 wrapped onto another
line so that the format looks like this:
Reference:
1. document 1
more of document 1 here
2. document 2
Comments:
I cannot change the format of the input I receive, so I have to find a way
to parse this the way I receive it. Any help would be highly appreciated.
Thank you.
------------------------------
Date: Mon, 15 Nov 2004 17:12:41 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Need RegExp
Message-Id: <slrncpidv9.1eg.tadmc@magna.augustmail.com>
Indigo5 <abc@microsoft.com> wrote:
> I need a way of parsing a variable format. Basically the section starts off
> with a Reference keyword and ends with a Comments keyword.
Have you considered using $/ instead?
Maybe $/ = "Comments:\n"; # ??
> Reference:
> 1. document1
> 2 document2
> Comments:
>
> I was doing this as follows:
>
> if (/^Reference/ .. /^Comments/){
>
> if (/^[0-9]/){
>
> chomp;
>
> $_ =~ s/^[0-9].\s+//g;
>
> push @references, $_;
> }
> }
>
> However, I just received a document where Reference 1 wrapped onto another
> line so that the format looks like this:
>
> Reference:
> 1. document 1
> more of document 1 here
So just tack it onto the end of the previous one then.
What's the problem?
if ( /^ +/ ) { # continuation line
chomp;
$references[-1] .= " $_";
}
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 15 Nov 2004 22:40:48 +0100
From: phill hw <phill@mywebstuff.com>
Subject: problems using taint to check an array be created by cgi
Message-Id: <pan.2004.11.15.21.40.33.966125@mywebstuff.com>
Hello Usenet Perl,
I have a html form which produces a load of checkboxes. They all have the
same name (sports) and if a check box is ticked(checked) it holds a numeric value
which represents the id of the sport.:
Pseudo CGI FORM:
<FORM>
<input type="text" name="s" value="aslakslad1231">
<p><input type="checkbox" name="sport" value="1">Football</p>
<p><input type="checkbox" name="sport" value="2">Basketball</p>
<p><input type="checkbox" name="sport" value="3">Hockey</p>
<SUBMIT BUTTON>
</FORM>
When the form data is send to the cgi script for processing:
This works with taint on, but I have to parse the values in the @sports
array and put them into another array (@tsports) before I can use them. If I do
not use this second array the data in the @sports array is still considered
tainted and I cannot use it:
#!/usr/bin/perl -Tw
use strict;
use CGI qw/:standard :html3/;
use CGI::Carp 'fatalsToBrowser';
if (param())
{
my ($query) = new CGI;
my ($s) = $query->param('s') =~ /^([\w]+)$/ if $query->param('s');
my (@sports) = $query->param('sports');
my (@tsports);
foreach(@sports)
{
if ($_ =~ /^([\d]+)$/)
{
push(@tsports, $_);
}
}
}
If I use the following script, I cannot use the data contained in the @sports array
as it is still considered tainted.
#!/usr/bin/perl -Tw
use strict;
use CGI qw/:standard :html3/;
use CGI::Carp 'fatalsToBrowser';
if (param())
{
my ($query) = new CGI;
my ($s) = $query->param('s') =~ /^([\w]+)$/ if $query->param('s');
my (@sports) = $query->param('sports')=~ /^([\d]+)$/ if $query->param('sports');
}
How can I correctly parse the @sports array to allow for numbers only without
having to construct a second array? Is this possible or doe I hav to
parse the contents of the first array and effectively do a taint check on each value
contained in the first array?
Thankyou
Phill
------------------------------
Date: 15 Nov 2004 23:43:05 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: problems using taint to check an array be created by cgi
Message-Id: <Xns95A2BE68E8CBCasu1cornelledu@132.236.56.8>
phill hw <phill@mywebstuff.com> wrote in
news:pan.2004.11.15.21.40.33.966125@mywebstuff.com:
> Hello Usenet Perl,
> I have a html form which produces a load of checkboxes. They all have
> the same name (sports) and if a check box is ticked(checked) it holds
> a numeric value which represents the id of the sport.:
>
> Pseudo CGI FORM:
> <FORM>
> <input type="text" name="s" value="aslakslad1231">
> <p><input type="checkbox" name="sport" value="1">Football</p>
> <p><input type="checkbox" name="sport" value="2">Basketball</p>
> <p><input type="checkbox" name="sport" value="3">Hockey</p>
> <SUBMIT BUTTON>
> </FORM>
May I suggest that this is probably not a good way to set up the form? Life
would probably be easier if you had, e.g.
<p><input type="checkbox" name="sport" value="Hockey">Hockey</p>
> This works with taint on, but I have to parse the values in the
You are not parsing them, you are untaiting them. The difference is
important.
Here is how I might do it although I would urge you to take it with a grain
of salt:
use strict;
use warnings;
use Data::Dumper;
my %valid = map { $_ => 1 } qw(Basketball Football Hockey);
my @sports = qw(Basketball Hockey /etc/password);
@sports = map { $valid{$_} ? ($_) = ( $_ =~ /^(.+)$/ ) : '' } @sports;
print Dumper \@sports;
__END__
All of the code I show below is untested.
> #!/usr/bin/perl -Tw
use warnings;
rather than -w.
> use CGI qw/:standard :html3/;
Below, you use only the object interface, so a
use CGI;
would suffice here.
> use CGI::Carp 'fatalsToBrowser';
>
> if (param())
This is very unnecessary. Just contruct your CGI object.
> {
> my ($query) = new CGI;
> my ($s) = $query->param('s') =~ /^([\w]+)$/ if $query->param('s');
A few errors and style issues here. Your code would fail to untaint $s if
$query->param('s') returned '0' or '0E0' or '0 but true'. Also, I remember
discussions where it was mentioned that
my $s = 'something' if some other thing;
is not really a safe construct.
You are better off actually spelling out what you are doing:
my $s = $query->param('s');
if(defined $s and $s =~ /^(\w+)$/) {
$s = $1;
} else {
$s = '';
}
\w itself is a character class. I am not sure [\w] is an error but is
unnecessary and confusing.
> my (@sports) = $query->param('sports');
I'll recommend setting up a hash of acceptable values for sports as above
and using the keys to validate the values. If the value is a key in %valid,
then you know it is safe to blindly capture it.
> if ($_ =~ /^([\d]+)$/)
Again, \d is a character class of its own. And, by the way, is
987327332882727273774746655222411313232638482929399949872873498238971232838
123847328723984792837482374982374621347326473624723648723648732648726423444
23424 a valid value for sports?
Sinan.
------------------------------
Date: 15 Nov 2004 17:39:29 -0800
From: google@servangle.net (John R)
Subject: RegEx challenge - jrs
Message-Id: <100a40e5.0411151739.519e8b59@posting.google.com>
I'm puzzled on how to make the following regex work:
String(1):
dsr:"Some text"; height:67; width:10; client:"seven"
String(2):
dsr:"Some;text"; height:67; width:10; client:"seven"
RegEx applied:
(\w+):?([^;]+)?;\s?
String(1) parsed great, resulting in two arrays:
dsr "Some text"
height 67
width 10
client "seven"
However, string(2) will not parse correctly because it has an extra
";" between the quotes:
Can regex ignore ; if they are between quotes?
------------------------------
Date: 16 Nov 2004 02:02:57 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: RegEx challenge - jrs
Message-Id: <Xns95A2D6215D1Casu1cornelledu@132.236.56.8>
google@servangle.net (John R) wrote in news:100a40e5.0411151739.519e8b59
@posting.google.com:
> I'm puzzled on how to make the following regex work:
>
> String(1):
> dsr:"Some text"; height:67; width:10; client:"seven"
> String(2):
> dsr:"Some;text"; height:67; width:10; client:"seven"
Yeah whatever ... An almost identical question was posted and answered
withing the last couple of days. Doesn't anyone lurk and read the FAQ any
more?
perldoc -q inside
By the way:
> RegEx applied:
> (\w+):?([^;]+)?;\s?
>
> String(1) parsed great, resulting in two arrays:
What do you mean "resulting in two arrays"?
use strict;
use warnings;
my @data;
while(<DATA>) {
if( /^dsr:(".+"); height:(\d+); width:(\d+); client:(".+")\s*$/ ) {
push @data, {
dsr => $1,
height => $2,
width => $3,
client => $4,
};
}
}
use Data::Dumper;
print Dumper \@data;
__DATA__
dsr:"Some text"; height:67; width:10; client:"seven"
dsr:"Some;text"; height:67; width:10; client:"seven"
--
A. Sinan Unur
1usa@llenroc.ude.invalid
(remove '.invalid' and reverse each component for email address)
------------------------------
Date: 15 Nov 2004 12:35:30 -0800
From: gspk@yahoo.com (Prince Kumar)
Subject: Re: replace pattern including newline : perl version 5.8
Message-Id: <629275ba.0411151235.27aa03e5@posting.google.com>
Thank you very much!!!
"John W. Krahn" <someone@example.com> wrote in message news:<_4ald.149209$df2.118815@edtnps89>...
> Prince wrote:
> >
> > "John W. Krahn" <someone@example.com> wrote in message news:<7PThd.85034$9b.53687@edtnps84>...
> >
> >>Prince Kumar wrote:
> >>
> >>>I have a file with the following contents.
> >>>
> >>>drop table tabl1;
> >>>
> >>>create table tabl1 (
> >>>col1
> >>>col2
> >>>col3);
> >>>
> >>>drop table tabl2;
> >>>
> >>>create table tabl2 (
> >>>col1
> >>>col2);
> >>>
> >>>..
> >>>
> >>>I want to replace "create table * );" with
> >>>"create table * ) IN TBSP1;"
> >>>
> >>>I tried the following, but I am not getting the desired result.
> >>>
> >>>perl -p -e 'undef $/; s/^CREATE TABLE (.*?)\);$/CREATE TABLE $1 \) IN
> >>>TBSP/s' my_input_file.
> >>
> >>perl -073pe's/^(\s*create\s+table\s+(\S+)\s+\((?s:.+?)\));/$1 IN \U$2;/i'
> >>my_input_file
> >
> > The given solution works perfect. What does -073 option do?
>
> -073 uses the character ';' as the input record separator
>
>
> > Would you also, please explain "((?s:.+?)\))". I tried the perlre, but
> > couldn't understand completely.
>
> That says match a literal '(' character followed by one or more of any
> character including the newline character followed by a literal ')' character.
> Normally .+? will not match a newline so you need the /s option to allow it
> to match any character. You could also write it like this:
>
> perl -073pe's/^(\s*create\s+table\s+(\S+)\s+\(.+?\));/$1 IN \U$2;/si'
> my_input_file
>
>
>
> John
------------------------------
Date: Mon, 15 Nov 2004 13:09:26 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Sending email using perl
Message-Id: <151120041309266035%jgibson@mail.arc.nasa.gov>
In article <Pine.LNX.4.58.0411151319001.30202@brok.diku.dk>, Lars
Roland <roland@diku.dk> wrote:
> Hi all
>
> I use the folowing script to send email directly to a server (using its ip
> address), my problem is that the script nerver halts (eg. its while loop
> semas to run forever), can someone in here see why this is so ? as I can
> not understand this:
>
> --------------------------------------------
> #!/usr/bin/perl
> use strict;
> use MIME::Entity;
> my $mailhost = shift(@ARGV);
> my $recip = shift(@ARGV);
> my $sender = shift(@ARGV);
> my $subject = shift(@ARGV);
> my $nrofmsg = shift(@ARGV);
> if ($mailhost =~ /--help/)
> {
> die "usage: mail.pl smtp-server recipient sender subject nrofmails.
> The e-mail body is empty"
> };
> my $nrofsend = 1;
> #the e-mail
> my $message;
> $message="Test";
> while( $nrofsend <= $nrofmsg)
> {
> fork;
One problem in your script is that you are not using the return value
of fork to determine whether the thread of execution that follows is
the parent or child process. Thus, both the parent and child will
attempt to send the e-mail. What is worse, each child will attempt to
fork other children, which will also attempt to send an e-mail. While
the whole mess should eventually stop forking processes, it is probably
not what you want.
See 'perldoc -f fork', 'perldoc perlfork', and 'perldoc perlipc' for
examples using fork(). I am afraid none of these references look very
informative with simple examples of using fork. Search for 'Interactive
Client with IO::Socket' in 'perldoc perlipc' for one almost good
example.
The basic fork sequence is like:
my $pid = fork();
if( $pid ) {
# parent process
}elsif( defined $pid ) {
# child process
}else{
# fork failed
}
You normally also need some mechanism for the parent to wait for the
child processes to terminate, using the wait() or waitpid() functions
and possibly the CHLD signal.
Given the complexity, you might also want to ask yourself why you need
to fork at all. It might be better to get your program working without
the fork first.
[ rest of programm snipped ]
------------------------------
Date: Tue, 16 Nov 2004 01:38:07 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: Two operations with one last if?
Message-Id: <Xns95A2D1E9F1075dkwwashere@216.168.3.30>
Uri Guttman <uguttman@athenahealth.com> wrote:
>>>>>> "DKW" == David K Wall <dwall@fastmail.fm> writes:
>
> DKW> if ($foo eq 'bar' or $foo eq 'baz') {
> DKW> # do something
> DKW> }
>
> that is still an expression. ||/&& has always bound tighter than
> the comparision ops since they are meant to join those into
> larger boolean expressions. this is classic precedence stuff in
> many languages.
I think I'll quit while I'm behind. I understand what you mean, but
my brain keeps insisting on the wrong interpretation. :-)
------------------------------
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 7407
***************************************