[24599] in Perl-Users-Digest
Perl-Users Digest, Issue: 6775 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 7 18:05:51 2004
Date: Wed, 7 Jul 2004 15:05:11 -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 Wed, 7 Jul 2004 Volume: 10 Number: 6775
Today's topics:
A doubt about m//'s related variables <bik.mido@tiscalinet.it>
Re: A doubt about m//'s related variables <pinyaj@rpi.edu>
Re: Auto die on failed sys calls? (Anno Siegel)
Re: Auto die on failed sys calls? <krahnj@acm.org>
Re: Injecting variables after the import subroutine has (Daniel S.)
manipulating a hash of hashes <aaron@deloachcorp.com>
Re: manipulating a hash of hashes <mritty@gmail.com>
Re: manipulating a hash of hashes <pinyaj@rpi.edu>
Re: manipulating a hash of hashes <bmb@ginger.libs.uga.edu>
Re: Newbie: How do I filter output to the screen and w (Mav)
Re: Newbie: How do I filter output to the screen and w <noreply@gunnar.cc>
Re: Newbie: How to I extract word (Mav)
Re: Not sure if Perl or browser problem..... <scottjou@farnell.ns.ca>
Re: Passing args to a running thread... <odyniec-usenet@odyniec.net>
Re: pattern matching <scottjou@farnell.ns.ca>
Re: Perl and modems <tim@-123nospan-mtgallagher.com>
Re: problem with a script in perl. <Joe.Smith@inwap.com>
Regular expression to match surrounding parenthesis (Bob)
Re: Regular expression to match surrounding parenthesis <noreply@gunnar.cc>
Re: Regular expression to match surrounding parenthesis <abigail@abigail.nl>
Re: Regular expression to match surrounding parenthesis (Peter J. Acklam)
Re: Setting environment variables from a Perl script <ddunham@redwood.taos.com>
Re: sorting hash based on keys and replacing them in <scottjou@farnell.ns.ca>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 07 Jul 2004 21:56:41 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: A doubt about m//'s related variables
Message-Id: <02loe09r0iv2oq90g5ijvp9mfe87jkqkqc@4ax.com>
I have a minor doubt about predefined variables related to pattern
matching: in particular is it safe to do something like this?
if ( /\{([\w:]+)\}/ ) {
do_something($`, $', split /:/, $1);
}
I mean: are $`, $' and $1 those coming from the
*first* pattern matching in all cases?
Michele
--
#!/usr/bin/perl -lp
BEGIN{*ARGV=do{open $_,q,<,,\$/;$_}}s z^z seek DATA,11,$[;($,
=ucfirst<DATA>)=~s x .*x q^~ZEX69l^^q,^2$;][@,xe.$, zex,s e1e
q 1~BEER XX1^q~4761rA67thb ~eex ,s aba m,P..,,substr$&,$.,age
__END__
------------------------------
Date: Wed, 7 Jul 2004 16:38:17 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: A doubt about m//'s related variables
Message-Id: <Pine.SGI.3.96.1040707163611.36335B-100000@vcmr-64.server.rpi.edu>
On Wed, 7 Jul 2004, Michele Dondi wrote:
>I have a minor doubt about predefined variables related to pattern
>matching: in particular is it safe to do something like this?
>
> if ( /\{([\w:]+)\}/ ) {
> do_something($`, $', split /:/, $1);
> }
>
>I mean: are $`, $' and $1 those coming from the
>*first* pattern matching in all cases?
You could have determined that on your own with testing. As it stands,
yes they are. I'm a little surprised about $` and $', but that's because
split() doesn't affect them. Had you done:
if ( /\{([\w:]+)\}/ ) {
do_something($`, $', $1 =~ /[^:]*/g);
}
you would get rather unexpected results.
I also advise against using $` and $' and $& if you can avoid them.
--
Jeff "japhy" Pinyan % How can we ever be the sold short or
RPI Acacia Brother #734 % the cheated, we who for every service
RPI Corporation Secretary % have long ago been overpaid?
http://japhy.perlmonk.org/ %
http://www.perlmonks.org/ % -- Meister Eckhart
------------------------------
Date: 7 Jul 2004 15:38:23 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Auto die on failed sys calls?
Message-Id: <cch5df$5rg$1@mamenchi.zrz.TU-Berlin.DE>
John W. Krahn <krahnj@acm.org> wrote in comp.lang.perl.misc:
> J Krugman wrote:
> >
> > Is there any way to instruct perl to die whenever a system call
> > (e.g. through open, opendir, backticks, system, etc.) fails?
> >
> > The aim is to be able to enclose a series of such calls in a single
> > eval block, and catch any failures at the end, instead of checking
> > for them after each system call.
>
> perldoc Fatal
Ah... interesting. Thanks for mentioning it, I never noticed that
module.
Anno
------------------------------
Date: Wed, 07 Jul 2004 20:18:17 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Auto die on failed sys calls?
Message-Id: <40EC5A7D.72AC64BA@acm.org>
Anno Siegel wrote:
>
> John W. Krahn <krahnj@acm.org> wrote in comp.lang.perl.misc:
> > J Krugman wrote:
> > >
> > > Is there any way to instruct perl to die whenever a system call
> > > (e.g. through open, opendir, backticks, system, etc.) fails?
> > >
> > > The aim is to be able to enclose a series of such calls in a single
> > > eval block, and catch any failures at the end, instead of checking
> > > for them after each system call.
> >
> > perldoc Fatal
>
> Ah... interesting. Thanks for mentioning it, I never noticed that
> module.
You learn something new every day. :-) At least I know I do.
John
--
use Perl;
program
fulfillment
------------------------------
Date: 7 Jul 2004 12:54:27 -0700
From: lachinois@hotmail.com (Daniel S.)
Subject: Re: Injecting variables after the import subroutine has been called?
Message-Id: <bdcf9711.0407071154.4298c5d4@posting.google.com>
Paul Lalli <mritty@gmail.com> wrote in message news:<20040707102738.N22150@barbara.cs.rpi.edu>...
> On Wed, 7 Jul 2004, Daniel S. wrote:
>
> > Hi!
> >
> > I'm the author of the Regexp::Extended module and I'm trying to inject
> > variables into the main perl module (like the Exporter module does).
> >
> > I'm using overload:constant to modify regexp expressions and there is
> > an extension for named groups (?<var>pattern). However, if I try to
> > export '$var' at the time overload:constant is being called (after the
> > import sub has been executed) all I get is a segfault.
> >
> > Is there a way of exporting variables during the execution of a perl
> > code short of using $::var?
>
> Er, is there a reason you can't just use the import function in your main
> code?
>
>
> #!/usr/bin/perl
> use strict;
> use warnings;
> use MyMod('$foo');
>
> print "Module's foo value: $foo\n";
>
> import MyMod ('$bar');
> print "Module's bar value: $bar\n";
>
> __END__
>
> Of course, MyMod in this case would still have to have $bar in it's
> @EXPORT_OK array.
>
>
> 'use' is nothing more than a call to require and import wrapped in a
> BEGIN{} block.
>
> Paul Lalli
Well the problem happens to be that people declare named pattern
groups like this:
"1-2-2003" =~ /(?<date>\d+-\d+-\d+)/;
which gets coded as:
"1-2-2003" =~ /(\d+-\d+-\d+)(?{ $date = $^N })/;
However, $date has never been declared so I get a bit fat error
message at compilation under strict.
What I can do is this:
"1-2-2003" =~ /(?<date>\d+-\d+-\d+)(?{ $::date = $^N })/;
But its a pain to have to say $::date afterwards instead of plain
$date.
Daniel S.
------------------------------
Date: Wed, 7 Jul 2004 15:23:42 -0500
From: "Aaron DeLoach" <aaron@deloachcorp.com>
Subject: manipulating a hash of hashes
Message-Id: <OsydnXZ6AO9SxnHdRVn-iQ@eatel.net>
Hi all,
I have the following HoH:
my %payment_methods =
(
"Credit Cards"=>{
"ae" => "American Express",
"di" => "Discover",
"vi" => "Visa",
"jc" => "JCB",
"dc" => "Diners Club",
"mc" => "MasterCard",
},
"Other"=>{
"mo" => "Money Order",
"po" => "Purchase Order",
},
"Checks"=>{
"pe" => "Personal Check",
"co" => "Company Check",
"ca" => "Cashiers Check",
"ce" => "Certified Check",
},
);
I would like to construct an html table of the data as follows. I don't need
help with the html, just the ability to produce the data in column/row
format.
(hash names)
row1 Credit Cards | Other | Check
(now values)
row2 American express | Money Order | Company Check
row3 Discover | Purchase Order | Cashiers Check
row4 Visa | | Certified Check
row5 JCB | |
row6 Diners Club | |
and so on...
As you can see from the example data ends in different columns as the hash
runs out of values. Any assistance would be greatly appreciated.
Regards
Aaron
------------------------------
Date: Wed, 7 Jul 2004 16:54:51 -0400
From: Paul Lalli <mritty@gmail.com>
Subject: Re: manipulating a hash of hashes
Message-Id: <20040707165238.A22150@barbara.cs.rpi.edu>
On Wed, 7 Jul 2004, Aaron DeLoach wrote:
> Hi all,
>
> I have the following HoH:
>
> my %payment_methods =
> (
> "Credit Cards"=>{
> "ae" => "American Express",
> "di" => "Discover",
> "vi" => "Visa",
> "jc" => "JCB",
> "dc" => "Diners Club",
> "mc" => "MasterCard",
> },
> "Other"=>{
> "mo" => "Money Order",
> "po" => "Purchase Order",
> },
> "Checks"=>{
> "pe" => "Personal Check",
> "co" => "Company Check",
> "ca" => "Cashiers Check",
> "ce" => "Certified Check",
> },
> );
>
> I would like to construct an html table of the data as follows. I don't need
> help with the html, just the ability to produce the data in column/row
> format.
>
> (hash names)
> row1 Credit Cards | Other | Check
> (now values)
> row2 American express | Money Order | Company Check
> row3 Discover | Purchase Order | Cashiers Check
> row4 Visa | | Certified Check
> row5 JCB | |
> row6 Diners Club | |
>
> and so on...
>
> As you can see from the example data ends in different columns as the hash
> runs out of values. Any assistance would be greatly appreciated.
Don't try to do what's already been done before. Use a module that's
already written, like HTML::Table, available on CPAN:
#!/usr/bin/perl
use strict;
use warnings;
use HTML::Table
my %payment_methods =
(
"Credit Cards"=>{
"ae" => "American Express",
"di" => "Discover",
"vi" => "Visa",
"jc" => "JCB",
"dc" => "Diners Club",
"mc" => "MasterCard",
},
"Other"=>{
"mo" => "Money Order",
"po" => "Purchase Order",
},
"Checks"=>{
"pe" => "Personal Check",
"co" => "Company Check",
"ca" => "Cashiers Check",
"ce" => "Certified Check",
},
);
my $table = new HTML::Table;
foreach $type (keys %payment_methods) {
$table->addCol($type, values(%{$payment_methods{$type}}));
}
print $table->getTable, "\n";
__END__
(note that formatting, for example the column headings, is left as an
excercise to the reader. It should be possible once you've read the
documentation for HTML::Table)
Paul Lalli
------------------------------
Date: Wed, 7 Jul 2004 17:03:13 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: Aaron DeLoach <aaron@deloachcorp.com>
Subject: Re: manipulating a hash of hashes
Message-Id: <Pine.SGI.3.96.1040707163845.36335D-100000@vcmr-64.server.rpi.edu>
[posted & mailed]
On Wed, 7 Jul 2004, Aaron DeLoach wrote:
[reformatted]
>Credit | Other | Check
>===========================================
>AmEx | Money Order | Company Check
>Disc | Purchase Order | Cashiers Check
>Visa | | Certified Check
>JCB | | Personal Check
>Diner | |
>As you can see from the example data ends in different columns as the hash
>runs out of values. Any assistance would be greatly appreciated.
I would first get the data out of the hashrefs:
my @data = map [values %$_], values %payment_methods;
This gets us from:
my %payment_methods = (
"Credit Cards" => {
"ae" => "American Express",
"di" => "Discover",
"vi" => "Visa",
"jc" => "JCB",
"dc" => "Diners Club",
"mc" => "MasterCard",
},
"Other"=>{
"mo" => "Money Order",
"po" => "Purchase Order",
},
"Checks"=>{
"pe" => "Personal Check",
"co" => "Company Check",
"ca" => "Cashiers Check",
"ce" => "Certified Check",
},
);
to this:
@data = (
[ "American Express", "Discover", "Visa", ... ],
[ "Money Order", "Purchase Order" ],
[ "Personal Check", "Company Check", ... ],
);
though not necessarily in those orders. Now we need to know the dimension
of the largest hashref (now arrayref):
my $max = 0;
for (@data) { $max = @$_ if $max < @$_ }
Now we can do this in a naive manner or a more cunning manner:
print "<table>\n";
for my $i (0 .. $max-1) {
print "<tr>\n";
for (@data) {
print "<td>$_->[$i]</td>";
}
print "\n</tr>\n";
}
print "</table>\n";
That's naive, because you'll be getting empty cells whenever an arrayref
"runs out" of elements. The more cunning way is to insert "rowspan"
attributes when an array is on its last element, and then to skip that
array afterwards.
print "<table>\n";
for my $i (0 .. $max-1) {
print "<tr>\n";
for (@data) {
# skip if we're past the end
next if $#$_ < $i;
# if this is the last element, make its rowspan bigger
my $span = ($#$_ == $i) ? $max - $#$_ : 1;
print "<td rowspan=$span valign='top'>$_->[$i]</td>";
}
print "\n</tr>\n";
}
print "</table>\n";
--
Jeff "japhy" Pinyan % How can we ever be the sold short or
RPI Acacia Brother #734 % the cheated, we who for every service
RPI Corporation Secretary % have long ago been overpaid?
http://japhy.perlmonk.org/ %
http://www.perlmonks.org/ % -- Meister Eckhart
------------------------------
Date: Wed, 7 Jul 2004 17:17:24 -0400
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: manipulating a hash of hashes
Message-Id: <Pine.A41.4.58.0407071706030.41664@ginger.libs.uga.edu>
On Wed, 7 Jul 2004, Aaron DeLoach wrote:
> Hi all,
>
> I have the following HoH:
>
> my %payment_methods =
> (
> "Credit Cards"=>{
> "ae" => "American Express",
> "di" => "Discover",
> "vi" => "Visa",
> "jc" => "JCB",
> "dc" => "Diners Club",
> "mc" => "MasterCard",
> },
> "Other"=>{
> "mo" => "Money Order",
> "po" => "Purchase Order",
> },
> "Checks"=>{
> "pe" => "Personal Check",
> "co" => "Company Check",
> "ca" => "Cashiers Check",
> "ce" => "Certified Check",
> },
> );
>
> I would like to construct an html table of the data as follows. I don't need
> help with the html, just the ability to produce the data in column/row
> format.
>
> (hash names)
> row1 Credit Cards | Other | Check
> (now values)
> row2 American express | Money Order | Company Check
> row3 Discover | Purchase Order | Cashiers Check
> row4 Visa | | Certified Check
> row5 JCB | |
> row6 Diners Club | |
>
> and so on...
>
> As you can see from the example data ends in different columns as the hash
> runs out of values. Any assistance would be greatly appreciated.
>
> Regards
> Aaron
Below is another solution using a module. I cheated and used 'sort' in a
couple of places. If you really want the order you show above, then
replace sort with a different method. :-)
use Array::Each;
my @headings = sort keys %payment_methods;
my $set = Array::Each->new(
set => [ map [sort values %$_],
@payment_methods{ @headings }, ],
undef => ' ',
bound => 0,
count => 1,
);
print
"<table border='1'>\n",
"<tr> <td></td>",
map( "<th>$_</th> ", @headings ),
"</tr>\n";
while( my @row = $set->each ) {
printf "<tr> <td>row%d.</td> ", pop @row;
print map( "<td>$_</td> ", @row ), "</tr>\n";
}
print "</table>\n";
Regards,
Brad
--
http://search.cpan.org/~bbaxter/Array-Each-0.02/Each.pm
------------------------------
Date: 7 Jul 2004 13:56:41 -0700
From: mluvw47@yahoo.com (Mav)
Subject: Re: Newbie: How do I filter output to the screen and writing the orginal output to a file?
Message-Id: <dfaafecd.0407071256.4ecf6256@posting.google.com>
Thanks Gunnar. That is exactly the answer I am looking for.
If I use system(@args) I can get a $buildResult from it.
$buildResult = system(@args); (That will give me return 0 if build successful).
Now, if I am using open:
open my $proc, "@args |" or die $!;
Is that anyway I can get the $buildResult?
Thanks,
Mav
Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in message news:<2l2b6vF7qbtbU1@uni-berlin.de>...
> Anno Siegel wrote:
> > Backticks and qx wait until the background process is finished and
> > deliver all the output at once. To see the lines of output as they
> > appear, open a filehandle to capture the output. Untested:
> >
> > open my $proc, "@args |";
> > /^(\s*--.+)/ and print "$1\n" while <$proc>;
>
> Thanks, Anno!
>
> So, then a solution to the OP's question may be:
>
> open my $log, '>> build.log' or die $!;
> open my $proc, "@args |" or die $!;
> while (<$proc>) {
> print $log $_;
> print if /^(\s*--.+)/;
> }
> close $proc;
> close $log;
------------------------------
Date: Wed, 07 Jul 2004 23:54:34 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Newbie: How do I filter output to the screen and writing the orginal output to a file?
Message-Id: <2l39pbF7odgcU1@uni-berlin.de>
Mav wrote:
> Thanks Gunnar. That is exactly the answer I am looking for.
Good, but don't forget to thank Anno who provided the actual solution...
> If I use system(@args) I can get a $buildResult from it.
> $buildResult = system(@args); (That will give me return 0 if build
> successful).
>
> Now, if I am using open:
> open my $proc, "@args |" or die $!;
> Is that anyway I can get the $buildResult?
You can check the return value from close():
close $proc or die "Build failed $! $?";
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 7 Jul 2004 15:00:52 -0700
From: mluvw47@yahoo.com (Mav)
Subject: Re: Newbie: How to I extract word
Message-Id: <dfaafecd.0407071400.4f1bc3a6@posting.google.com>
Thanks all, I think I should have said at the beginnig print the
string out, instead extract..
if ($line =~ /Project:(\s\w*)\,/) {
print "HERE:$1\n";
}
Thanks all,
Mav
Dale Henderson <nilram@hotpop.com> wrote in message news:<87k6xiglsm.fsf@camel.tamu-commerce.edu>...
> >>>>> "JS" == Joe Smith <Joe.Smith@inwap.com> writes:
>
> JS> Dale Henderson wrote:
> >> An equivalent way to do this is: (my $project = $string) =~
> >> s/.*Project:([^,]+),.*/$1/; However, this makes $project
> >> pointless since the replacement modifies $string to be the $1
> >> and then $project is assigned the value of $string.
>
> JS> No, it does not.
>
> JS> It copies the value of $string to the variable $project first,
> JS> and then performs the substitution on $project, leaving
> JS> $string untouched.
>
> Guess I should I have tested that too.
>
> Thanks for the correction.
------------------------------
Date: Wed, 07 Jul 2004 16:25:44 -0300
From: Scott J <scottjou@farnell.ns.ca>
Subject: Re: Not sure if Perl or browser problem.....
Message-Id: <t9joe0p530kt5g2emeabep0u1nftijv22a@4ax.com>
This baffled me for a minute too :)
You have loaded the CGI module, but you have not initialized it.
Change your script to reflect my changes :
#! C:\Perl\bin\perl
use CGI ':standard';
$query = new CGI;
print "Content-type: text/html\n\n";
$firstName = $query->param('firstName');
$lastName = $query->param('lastName');
print qq($lastName $firstName);
If this script is running on a windows machine, I remember reading how
using the qq() operator wont work, fyi.
print "$lastName $firstName"; # less typing this way too!
Scott
On 4 May 2004 08:10:48 -0700, jnunner@hotmail.com (Jamie) wrote:
>I think this is a browser or OS issue...but it seems nobody responds
>to those groups, lol...so I'm hoping someone here may be able to help
>since i'm using perl for the form processing...
>
>Is there something with IE6 on WinXP that would stop my HTML forms
>from processing the entered information to my perl script. I just
>switched
>systems from Win95 / IE5.5 (where the form and script worked fine), to
>XP Pro with IE6. I double & triple checked all the file/directory
>paths. The server and Perl Interpreter were both installed and set up
>with their respective default settings. The ACTION is pointing to the
>correct path & script name. The script is running when the submit
>button is clicked, but the form information is not being passed to the
>script for some reason. I'm baffled !!
>
>Can anyone help ?? Do you need more info ??
>
>I even did a simple test form and script to make sure I was doing
>everything correct and got the same results.
>
>
>
>FORM:
><form action="cgi-bin/Home.pl" method=post>
>First Name: <input type=text name="firstName"><br>
>Last Name: <input type=text name="lastName">
><p align=center><input type=submit value="Continue"><br><br></p>
></form>
>
>
>SCRIPT:
>#! C:\Perl\bin\perl
>use CGI ':standard';
>print "Content-type: text/html\n\n";
>
>$firstName = param('firstName');
>$lastName = param('lastName');
>
>print qq($lastName $firstName);
>
>
>
>....As you can see, this is a very basic form...but the names entered
>into the form do not get thru to the script and are not printing. But
>in my original sript, I'm also printing out HTML code, to format the
>output, which is printed to the screen without a problem.
>
>HELP !!
------------------------------
Date: 07 Jul 2004 19:16:30 +0200
From: Michal Wojciechowski <odyniec-usenet@odyniec.net>
Subject: Re: Passing args to a running thread...
Message-Id: <87isczu49d.fsf@orion.odyniec.net>
parizienne@parizienne.ch (..:: parizienne ::..) writes:
> I would like to have a program structure allowing me to pass args to
> a running thread in perl. I didn't see any topic on this anywhere. I
> think it is not possible with just a command.
[...]
I suppose you'll find all the answers you need in the tutorial on
threads in Perl - see 'perldoc perlthrtut'.
--
Michal Wojciechowski : for(<>){/\s/,$l{$m=$`}=$'}$_ : 10 PRINT "Yet another"
odyniec()odyniec;net : =$l{$c},/O\s/?$c=$'-1:y/"//d : 20 PRINT "Perl hacker"
http://odyniec.net : ,/T\s/?print$':0while$c++<$m : 30 GOTO 10
------------------------------
Date: Wed, 07 Jul 2004 16:16:31 -0300
From: Scott J <scottjou@farnell.ns.ca>
Subject: Re: pattern matching
Message-Id: <0cioe0lh2fdidi4hrcfn3t95virvjurgsl@4ax.com>
On 19 Apr 2004 18:58:30 -0700, tanlh_listing@hotmail.com (LiHui)
wrote:
>Can someone tell me what does this line do ?
>
>$line =~ m/^\|\s*\w\S*\s*(?:\|.+?){10,}\|$/o
>
>I know that it check to see if the line begin with "|" follow by
>whitespace, word, nonwhitespace and than I'm lost. What is s*(?:\|.+?)
>
>Any help will be greatly appreciate. Thanks LH
I'll give it a go :) My regex abilities are a bit rusty.
^\| line starts with |
\s* followed by 0 or more whitespaces
\w followed by an alphanumeric character
\S* followed by 0 or more non whitespaces
\s* followed by 0 or more whitespaces
(?:\|.+?){10,} is a quantified extended regex sequence (see below)
\|$ line ends with |
o switch tells the pattern to compile only once.
Quantified regex sequence :
(?:...) is a cluster only parenthesis, no capturing (thanks Camel
book) which I think means that the pattern matches, but does not store
the matched string in a variable. The remainder of this sequence is a
regular regex :
\| matches |
.+? matches one character, 1 or more times (minimally)
{10,} tells the pattern inside the () to match at least 10 times
Does that help or hinder?
Scott
------------------------------
Date: Wed, 7 Jul 2004 11:13:02 -0400
From: "timgerr" <tim@-123nospan-mtgallagher.com>
Subject: Re: Perl and modems
Message-Id: <cch424$sr3$1@newshost.mot.com>
Thanks, I will look into this.
--
TIM GALLAGHER
"Paul Lalli" <mritty@gmail.com> wrote in message
news:20040707093217.F22150@barbara.cs.rpi.edu...
> On Wed, 7 Jul 2004, timgerr wrote:
>
> > I want to write a script that will send information to the modem to
> > automate a phone queue that I have to call every say. I heard that this
> > can be done in perl but I am net to perl. Can someone point me in a
> > direction?
>
>
> How new to Perl are you? If you need to learn the basics, I point you to
> http://learn.perl.org
>
> If you are comfortable with the language, I point you to CPAN. This is
> the place you go when you wonder "Has anyone already done ____" in Perl?
> You start your search of CPAN at http://search.cpan.org.
>
> In this case, a search for "Modem" turned up this likely candidate:
> http://search.cpan.org/~cosimo/Device-Modem-1.36/docs/Modem.pod
>
> Paul Lalli
------------------------------
Date: Wed, 07 Jul 2004 17:58:19 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: problem with a script in perl.
Message-Id: <%QWGc.39842$%_6.37069@attbi_s01>
Andre wrote:
> if a line, in the attachemant is longer than 139 characteres, the complet
> output is screwed with line of differnet lenght, containing aditionnal
> characters (like "=" ) even outside the attachment.
Are you honoring all the MIME headers? If the message has been converted
to quoted-printable, then it needs to be unquoted. This applies to both
the plain text and the attachment portions of the message.
-Joe
------------------------------
Date: 7 Jul 2004 11:23:49 -0700
From: bob_nf@hotmail.com (Bob)
Subject: Regular expression to match surrounding parenthesis
Message-Id: <84c27559.0407071023.3aed77@posting.google.com>
Hi,
I am trying to create a regular expression to verify that user entered
data is surrounded by the same number of open and closed parenthesis.
For example: if 'a' was the expression I was trying to match then a,
(a), ((a)), (((a)))... (((((((a))))))) would all be valid.
I am not new to regular expressions but I am also not an expert. I
have spent hours searching for a solution but no luck.
Is this possible and if so any help would be appreciated?
Thanks
Bob
------------------------------
Date: Wed, 07 Jul 2004 20:47:02 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Regular expression to match surrounding parenthesis
Message-Id: <2l2uo4F83va7U1@uni-berlin.de>
Bob wrote:
> I am trying to create a regular expression to verify that user
> entered data is surrounded by the same number of open and closed
> parenthesis.
>
> For example: if 'a' was the expression I was trying to match then
> a, (a), ((a)), (((a)))... (((((((a))))))) would all be valid.
What about nesting?
The CPAN module Text::Balanced might be helpful.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 07 Jul 2004 19:09:53 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Regular expression to match surrounding parenthesis
Message-Id: <slrnceoik1.4g9.abigail@alexandra.abigail.nl>
Bob (bob_nf@hotmail.com) wrote on MMMCMLXIII September MCMXCIII in
<URL:news:84c27559.0407071023.3aed77@posting.google.com>:
[] Hi,
[]
[] I am trying to create a regular expression to verify that user entered
[] data is surrounded by the same number of open and closed parenthesis.
[]
[] For example: if 'a' was the expression I was trying to match then a,
[] (a), ((a)), (((a)))... (((((((a))))))) would all be valid.
[]
[] I am not new to regular expressions but I am also not an expert. I
[] have spent hours searching for a solution but no luck.
You spend hours looking? Where did you look? The place I would look
first, the documentation that comes with Perl, mentions a regular
expression doing this.
[] Is this possible and if so any help would be appreciated?
Try helping yourself first.
Abigail
--
perl -e '$_ = q *4a75737420616e6f74686572205065726c204861636b65720a*;
for ($*=******;$**=******;$**=******) {$**=*******s*..*qq}
print chr 0x$& and q
qq}*excess********}'
------------------------------
Date: 07 Jul 2004 21:19:50 +0200
From: pjacklam@online.no (Peter J. Acklam)
Subject: Re: Regular expression to match surrounding parenthesis
Message-Id: <llhvbp61.fsf@online.no>
bob_nf@hotmail.com (Bob) wrote:
> I am trying to create a regular expression to verify that user entered
> data is surrounded by the same number of open and closed parenthesis.
>
> For example: if 'a' was the expression I was trying to match then a,
> (a), ((a)), (((a)))... (((((((a))))))) would all be valid.
>
> I am not new to regular expressions but I am also not an expert. I
> have spent hours searching for a solution but no luck.
In stead of verifying directly that the input is correct, it it
probably simpler to remove everything you know is correct and see
if there is anything left:
1 while $input =~ s/\([^()]*\)//g;
print $input =~ /[()]/ ? "bad" : "ok";
The first line removes all matching, possibly nested, parantheses
and the second line checks to see if there are any parentheses
left.
Peter
--
#!/local/bin/perl5 -wp -*- mode: cperl; coding: iso-8859-1; -*-
# matlab comment stripper (strips comments from Matlab m-files)
s/^((?:(?:[])}\w.]'+|[^'%])+|'[^'\n]*(?:''[^'\n]*)*')*).*/$1/x;
------------------------------
Date: Wed, 07 Jul 2004 16:07:06 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: Setting environment variables from a Perl script
Message-Id: <KcVGc.12362$d83.1405@newssvr27.news.prodigy.com>
J. Romano <jl_post@hotmail.com> wrote:
> So this approach doesn't fare so well in Win32 DOS, but it looks to
> me that it works great in Unix. This goes against what the perldoc
> says, so if anybody knows a caveat about using this technique (on
> Unix) that I don't see, please speak up. But if there are no
> problems, then I would think that this popular dilemma has been
> solved.
This isn't the same shell, but a new one. As a result, any shell
variables you may have set in the session will be lost.
$ BAR="bar bar"
$ echo "$FOO - $BAR"
- bar bar
$ exec /tmp/perl
execing /usr/bin/bash
$ echo "$FOO - $BAR"
foo foo -
$
Depending on your shell, you may lose history (although many will use a
.history file which will maintain state). You'd certainly lose any
connections to associated jobs.
$ sleep 500 &
[1] 2255
$ jobs
[1]+ Running sleep 500 &
$ exec /tmp/perl
execing /usr/bin/bash
$ jobs
$
I wouldn't call the issue "solved" by this technique. It's another
option.
--
Darren Dunham ddunham@taos.com
Senior Technical Consultant TAOS http://www.taos.com/
Got some Dr Pepper? San Francisco, CA bay area
< This line left intentionally blank to confuse you. >
------------------------------
Date: Wed, 07 Jul 2004 15:59:03 -0300
From: Scott J <scottjou@farnell.ns.ca>
Subject: Re: sorting hash based on keys and replacing them in the same hash
Message-Id: <amhoe0hb273uku6tet6lthrstv2nioqdqa@4ax.com>
On Wed, 17 Mar 2004 08:12:04 -0600, "yamini" <yamini_rajan@nospam.com>
wrote:
>hi,
>
>%h=("z","zebra","a","alive","y","yahoo");
> foreach $key (sort(keys %h)) {
> print $key, '=', $h{$key}, "\n";
>}
>now it prints in the sorted order.But i want to replace the old keys with sorted keys, in the hash named %h ,with their respective values.
>Is there any way?
>
So in other words you want to sort your hash and keep it sorted??
This is redundant and as far as I know, not possible. Hash variables
are unsorted by definition.
Scott
------------------------------
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 6775
***************************************