[28822] in Perl-Users-Digest
Perl-Users Digest, Issue: 66 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jan 23 18:06:08 2007
Date: Tue, 23 Jan 2007 15:05:12 -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 Tue, 23 Jan 2007 Volume: 11 Number: 66
Today's topics:
Can some one help to translate Python code to Perl? wnjayantha@yahoo.com
Re: Can some one help to translate Python code to Perl? <glex_no-spam@qwest-spam-no.invalid>
Re: Can some one help to translate Python code to Perl? <john@castleamber.com>
Email-Find module jcharth@hotmail.com
Re: Email-Find module krakle@visto.com
Re: forum perl <bik.mido@tiscalinet.it>
Re: forum perl (NOSPAM)
Re: How to decode javascript encodeURI / encodeURICompo <nobull67@gmail.com>
Re: How to decode javascript encodeURI / encodeURICompo <nobull67@gmail.com>
Re: How to decode javascript encodeURI / encodeURICompo <cwilbur@chromatico.net>
Re: MAC Address Comparison <bik.mido@tiscalinet.it>
Re: MAC Address Comparison <doni.sekar@gmail.com>
Re: MAC Address Comparison <bik.mido@tiscalinet.it>
Re: MAC Address Comparison <doni.sekar@gmail.com>
Re: MAC Address Comparison <doni.sekar@gmail.com>
missing simple regex <jpreston@general-steel.com>
Re: missing simple regex <glex_no-spam@qwest-spam-no.invalid>
Re: missing simple regex (NOSPAM)
Re: missing simple regex <bik.mido@tiscalinet.it>
Re: missing simple regex <abigail@abigail.be>
passing parameters to a perl prgram using getopts <vaibhav.aparimit@gmail.com>
passing parameters to a perl prgram using getopts <vaibhav.aparimit@gmail.com>
Re: passing parameters to a perl prgram using getopts anno4000@radom.zrz.tu-berlin.de
Re: passing parameters to a perl prgram using getopts <vaibhav.aparimit@gmail.com>
Re: passing parameters to a perl prgram using getopts <vaibhav.aparimit@gmail.com>
Re: passing parameters to a perl prgram using getopts <glennj@ncf.ca>
Re: Pattern Matching and Extraction <bik.mido@tiscalinet.it>
Re: Pattern Matching and Extraction <doni.sekar@gmail.com>
Re: perl regexp question <jgibson@mail.arc.nasa.gov>
Statistics Extraction <doni.sekar@gmail.com>
Re: Statistics Extraction <bik.mido@tiscalinet.it>
Re: Statistics Extraction <doni.sekar@gmail.com>
Re: Statistics Extraction <DJStunks@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 23 Jan 2007 09:01:19 -0800
From: wnjayantha@yahoo.com
Subject: Can some one help to translate Python code to Perl?
Message-Id: <1169571679.554341.171920@s48g2000cws.googlegroups.com>
import urllib
import urllib2
from xml.dom import minidom
user="YourUserName"
password="YourPassword"
site='https://test.api.betfairgames.com/rest/v1/bet/order'
site=site+"?username="+user
xml_request1="""<postBetOrder
xmlns="https://api.betfairgames.com/rest/v1"
round="1" marketId="3829306" currency="GBP">
<betPlace>
<bidType>BACK</bidType>
<price>2.6</price>
<size>4</size>
<selectionId>658439</selectionId>
</betPlace>
</postBetOrder>"""
values = {'xmlRequest':xml_request}
data=urllib.urlencode(values)
req=urllib2.Request(site)
req.add_header('Content-Type', 'application/x-www-form-urlencoded')
req.add_header('gamexAPIAgent','maryBrown@AOL.com.myGames.4.0')
req.add_header('gamexAPIAgentInstance','0d69ee8290ee2f9b336c1f060e3497a5')
req.add_header('gamexAPIPassword',password)
req.add_header('Keep-Alive','300')
req.add_header('Proxy-Connection','keep-alive')
req.add_header('Content-Type','application/x-www-form-urlencoded')
req.add_header('Content-Length',str(len(data)))
req.add_data(data)
xmlresult = urllib2.urlopen(req)
xmlparser = minidom.parse(xmlresult)
print xmlparser.toxml()
------------------------------
Date: Tue, 23 Jan 2007 11:20:37 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Can some one help to translate Python code to Perl?
Message-Id: <45b64362$0$706$815e3792@news.qwest.net>
wnjayantha@yahoo.com wrote:
> import urllib
> import urllib2
> from xml.dom import minidom
use LWP;
use XML::Simple;
use strict;
use warnings;
> user="YourUserName"
my $user = 'YourUserName';
> password="YourPassword"
my $password = 'YourPassword';
>
> site='https://test.api.betfairgames.com/rest/v1/bet/order'
> site=site+"?username="+user
my $site =
'https://test.api.betfairgames.com/rest/v1/bet/order?username=' . $user;
>
> xml_request1="""<postBetOrder
[...]
> </postBetOrder>"""
my $xml_request1 = q{<postBetOrder
...
</postBetOrder>};
For the rest, read the documentation on LWP and XML::Simple:
perldoc LWP
perldoc lwpcook
perldoc XML::Simple
It's almost a cut & paste, while adding a few '$'s here and there.
>
> values = {'xmlRequest':xml_request}
> data=urllib.urlencode(values)
>
> req=urllib2.Request(site)
> req.add_header('Content-Type', 'application/x-www-form-urlencoded')
> req.add_header('gamexAPIAgent','maryBrown@AOL.com.myGames.4.0')
> req.add_header('gamexAPIAgentInstance','0d69ee8290ee2f9b336c1f060e3497a5')
> req.add_header('gamexAPIPassword',password)
> req.add_header('Keep-Alive','300')
> req.add_header('Proxy-Connection','keep-alive')
> req.add_header('Content-Type','application/x-www-form-urlencoded')
> req.add_header('Content-Length',str(len(data)))
> req.add_data(data)
>
> xmlresult = urllib2.urlopen(req)
> xmlparser = minidom.parse(xmlresult)
>
> print xmlparser.toxml()
>
------------------------------
Date: 23 Jan 2007 18:21:02 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Can some one help to translate Python code to Perl?
Message-Id: <Xns98C17DA24FE54castleamber@130.133.1.4>
"J. Gleixner" <glex_no-spam@qwest-spam-no.invalid> wrote:
> my $site =
> 'https://test.api.betfairgames.com/rest/v1/bet/order?username=' .
> $user;
use URI::Escape;
:
:
my $site = '...username=' . uri_escape( $user );
might be more safe, unless you're 100% sure it's not needed and then I
would use Perl (instead of "PHP" :-D ):
my $site = "...username=$user";
--
John Experienced Perl programmer: http://castleamber.com/
Perl help, tutorials, and examples: http://johnbokma.com/perl/
------------------------------
Date: 23 Jan 2007 12:21:25 -0800
From: jcharth@hotmail.com
Subject: Email-Find module
Message-Id: <1169583685.297327.43660@d71g2000cwa.googlegroups.com>
Hello Guys I am trying to extract all email from text file using the
Email-find module and put them in an array
but i cant seem to figure it out. when i give it a text sample it works
but it just prints the emails out. How can i put them in an array? or
just put them in a string variable?
thanks.
my $finder = Email::Find->new(sub {
my($email, $orig_email) = @_;
print "Found ".$email->format."\n";
return $orig_email;
});
$finder->find(\$text);
------------------------------
Date: 23 Jan 2007 13:16:22 -0800
From: krakle@visto.com
Subject: Re: Email-Find module
Message-Id: <1169586982.799615.162220@m58g2000cwm.googlegroups.com>
On Jan 23, 2:21 pm, jcha...@hotmail.com wrote:
> Hello Guys I am trying to extract all email from text file using the
> Email-find module and put them in an array
> but i cant seem to figure it out. when i give it a text sample it works
> but it just prints the emails out. How can i put them in an array? or
> just put them in a string variable?
> thanks.
>
> my $finder = Email::Find->new(sub {
> my($email, $orig_email) = @_;
> print "Found ".$email->format."\n";
> return $orig_email;
> });
> $finder->find(\$text);
The emails are printing out because you're printing them out. Hence the
print statement you are using. If you wish to add them to an array then
do so.
------------------------------
Date: Tue, 23 Jan 2007 20:03:28 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: forum perl
Message-Id: <8pmcr2pg8up5kum1v00ka4ag7pnm8ms4ed@4ax.com>
On Tue, 23 Jan 2007 05:55:43 +0100, "john.swilting"
<john.swilting@wanadoo.fr> wrote:
>Exist you he(it) of the forums perl
>There are solutions with php
>But I schedule(program) it perl not with php
>Sourceforge gives me 3000 solutions
>How to choose
I understand that you may not be a native English speaker - neither am
I. Whatever, may you try to explain yourself better? AIUI I can't
understand whether you're looking for (i) a web based forum about Perl
or (ii) a ready made forum cms written in Perl. While I am a Perl
enthusiast, in the latter case I wonder *why* you want it: why does
the implementation language matter for you? In any case you may
consider using a framework to write one yourself: very popular and
(reportedly) good ones are catalyst, maypole and jifty.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Tue, 23 Jan 2007 14:08:46 -0600
From: "Mumia W. (NOSPAM)" <paduille.4060.mumia.w+nospam@earthlink.net>
Subject: Re: forum perl
Message-Id: <ep5qk6$nuv$1@aioe.org>
On 01/23/2007 01:03 PM, Michele Dondi wrote:
> On Tue, 23 Jan 2007 05:55:43 +0100, "john.swilting"
> <john.swilting@wanadoo.fr> wrote:
>
>> Exist you he(it) of the forums perl
>> There are solutions with php
>> But I schedule(program) it perl not with php
>> Sourceforge gives me 3000 solutions
>> How to choose
>
> I understand that you may not be a native English speaker - neither am
> I. Whatever, may you try to explain yourself better? [...]
It's been suggested in msgid:<pKCdnYH7iehDszfYRVnyuQA@bt.com> that Mr.
Swilting is using Google's translation service to communicate with this
group.
automated translation + precise technical requirements = :-(
--
Windows Vista and your freedom in conflict:
http://techdirt.com/articles/20061019/102225.shtml
------------------------------
Date: 23 Jan 2007 05:14:26 -0800
From: "Brian McCauley" <nobull67@gmail.com>
Subject: Re: How to decode javascript encodeURI / encodeURIComponent ?
Message-Id: <1169558066.360718.253570@d71g2000cwa.googlegroups.com>
On Jan 19, 1:02 pm, "Cloink" <Cloink_Frigg...@ntlworld.com> wrote:
> Look Brian clever clogs McCauley, I spent hours trawling the web, don't
> come your "You haven't tried hard enough," sneering down your nose at
> me. The FAQ. THE faq. Which one? I frequently ask myself "Why o
> why?" but I don't think you meant that FAQ.
Sorry about that. As others have pointed out "The FAQ" (without
further qualification) in a Perl newsgroup means "The Perl FAQ".
Sometimes we forget that this is not as blinding obvious to everyone as
it seems to us.
> I am encoding using
> standardised javascript functions. I searched on those functions. I
> found nothing useful.
I think I've missed something here? What was it you were looking for? A
description of what those functions do? That's what you appeared to be
asking. You were asking a question about Javascript in a Perl
newsgroup.
You also asked for a Perl function that was the reverse - and that you
were promptly given in another branch of this thread by Michele Dondi
(with further clarification from me).
> Sorry if I used the wrong terminolgy when I said W3C,
Er? Who said you were wrong?
http://www.w3.org/International/O-URL-code.html
> Do you really need a link to the ECMAscript v3 definition of
> encodeURI/encodeURIComponent/decodeblahblah when you can look it up in
> the Rhino book?
What makes you think I have the Rhino book? Anyhow I can look them up
on the ECMA website and that does appear to answer your question. I'm a
little bemused that you are criticising me for not bothering to make
the trivial effort to look up the exact same information that you were
seeking. If it's trivial for me why should it be non-trivial for you?
> So if that's
> the way that javascript encodes it, bearing in mind that javascript
> communicates http requests with Perl a zillion times a day on the
> tinterweb, how come I'm finding it so hard to find a reference to a
> Perl function that decodes via the reverse algorithm?
Dunno, why you found it hard so find. Like I said it's a FAQ.
> Talking of algorithms, the only almost-useful bit of your reply doesn't
> actually explain the algorithm by which one reaches xC3xA9 from u00E9.
> Which would've been nice.
Sorry, yes, guilty as charged. I only gave you the _name_ of the
algorithm "utf-8" (as, of course, does the description
encodeURIComponent on the ECMA site and the description of
international URI encoding on the W3C site).
I accept that it would have been a good idea to have included a pointer
to an explaination of utf-8. (It would of course have been wasteful to
have pasted the whole explaination into usenet).
http://en.wikipedia.org/wiki/Utf8
However I only feel very sighly guilty about this. Putting "utf8" or
"utf-8" into google and hitting "I feel lucky" takes me directly to the
Wikipedia entry.
------------------------------
Date: 23 Jan 2007 10:15:37 -0800
From: "Brian McCauley" <nobull67@gmail.com>
Subject: Re: How to decode javascript encodeURI / encodeURIComponent ?
Message-Id: <1169576137.188709.109040@s48g2000cws.googlegroups.com>
On Jan 22, 9:12 am, "Ian" <ianatur...@gmail.com> wrote:
[ rudeness ]
> NONE of you actually came up with the answer, did you?).
> [..] don't bother with [...] replies, I won't be coming back to
> read them)
Well the OP isn't comming back (and we won't loose sleep over that) but
just for my own sanity would any on-lookers like to verify that where
weren't, in fact, any questions that the OP asked in this thread that
weren't answered by several people.
I'm fairly sure my first two posts in this thread answered everything
the OP asked and more. Can anyone imagine how the OP could justify the
assertion "NONE of you actually came up with the answer". Sometimes
people get like this because they expect to be spoon-fed the answer,
but in this case even that doesn't explain it because I _did_
spoon-feed him the answer:
use Encode;
use URI::Escape qw(uri_unescape);
my $decoded = decode_utf8 uri_unescape $encoded;
------------------------------
Date: 23 Jan 2007 16:05:14 -0500
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: How to decode javascript encodeURI / encodeURIComponent ?
Message-Id: <873b611mk5.fsf@mithril.chromatico.net>
>>>>> "BMcC" == Brian McCauley <nobull67@gmail.com> writes:
BMcC> I'm fairly sure my first two posts in this thread answered
BMcC> everything the OP asked and more. Can anyone imagine how the
BMcC> OP could justify the assertion "NONE of you actually came up
BMcC> with the answer". Sometimes people get like this because
BMcC> they expect to be spoon-fed the answer, but in this case
BMcC> even that doesn't explain it because I _did_ spoon-feed him
BMcC> the answer: [snip answer]
I've seen this happen often; someone asks a basic question, and one
person spoon-feeds an answer while others admonish him for not
checking the FAQ; the person focuses on the admonishment and
completely misses the answer.
Alternately, the OP was a clueless twit, incapable of recognizing an
answer even when spoon-fed to him. Given how he responded, either
theory works.
Charlton
--
Charlton Wilbur
cwilbur@chromatico.net
------------------------------
Date: Tue, 23 Jan 2007 19:51:08 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: MAC Address Comparison
Message-Id: <i4mcr2lne384p0nuhojilobqd9hh13qmom@4ax.com>
On 22 Jan 2007 16:27:23 -0800, rkb@i.frys.com wrote:
>As I mentioned earlier, it would be best to make the check case
>insensitive. If the user enters the correct address, but the case is
Good point!
>different than what's in the file, the test will fail. Also, I'd exit
>out of the loop if there is a match.
That's what intuitively I would do as well. But maybe the OP would
allow multiple matches, and I doubt he only wants to print the matched
mac address: he's probably interested in doing stuff with other data
from his input file.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 23 Jan 2007 12:03:35 -0800
From: "doni" <doni.sekar@gmail.com>
Subject: Re: MAC Address Comparison
Message-Id: <1169582615.461303.105410@13g2000cwe.googlegroups.com>
thanks a lot, guys for your valuable input.
Michele, $words[0] is in the same form as $match.
Thanks,
sekar
------------------------------
Date: Tue, 23 Jan 2007 21:51:19 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: MAC Address Comparison
Message-Id: <67tcr2t9qj58hrcvk5u0lneek9ds549cvc@4ax.com>
On 23 Jan 2007 12:03:35 -0800, "doni" <doni.sekar@gmail.com> wrote:
>thanks a lot, guys for your valuable input.
>Michele, $words[0] is in the same form as $match.
Please quote some content (not top-posting) when replying. Just to
know what we're talking about. Indeed we all guessed "$words[0] is in
the same form as $match". You just forgot chomp()ing.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 23 Jan 2007 12:59:08 -0800
From: "doni" <doni.sekar@gmail.com>
Subject: Re: MAC Address Comparison
Message-Id: <1169585948.820695.81330@s48g2000cws.googlegroups.com>
Michele Dondi wrote:
> Please quote some content (not top-posting) when replying. Just to
> know what we're talking about. Indeed we all guessed "$words[0] is in
> the same form as $match". You just forgot chomp()ing.
>
Now, I understood what actually top-posting meant from your reply...
thanks,
sekar
------------------------------
Date: 23 Jan 2007 13:26:59 -0800
From: "doni" <doni.sekar@gmail.com>
Subject: Re: MAC Address Comparison
Message-Id: <1169587618.474485.284830@d71g2000cwa.googlegroups.com>
Michele Dondi wrote:
> Please quote some content (not top-posting) when replying. Just to
> know what we're talking about. Indeed we all guessed "$words[0] is in
> the same form as $match". You just forgot chomp()ing.
>
Now, I understood what actually top-posting meant from your reply...
thanks,
sekar
------------------------------
Date: Tue, 23 Jan 2007 13:36:27 -0600
From: "Jerry" <jpreston@general-steel.com>
Subject: missing simple regex
Message-Id: <12rcotu7ckk1ef1@corp.supernews.com>
I am reading lines from a file that I need to breakdown.
(yes, using strick)
$_ = "<var>StmtBal,7,60,19</var>";
/^\<(\w+)>(\w+),(\d+),(\d+),(\d+)/
The above works fine for "<var>StmtBal,7,60,19</var>". I get the following:
var
StmtBal
7
60
19
But not for "<var>Acct#,5,0,1</var>" or
"<var>.........Description..........,30,16,6</var>".
How do I handle the "#", "*" etc and ".."?
Thanks,
Jerry
------------------------------
Date: Tue, 23 Jan 2007 13:47:40 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: missing simple regex
Message-Id: <45b665da$0$709$815e3792@news.qwest.net>
Jerry wrote:
> I am reading lines from a file that I need to breakdown.
>
> (yes, using strick)
strict?
>
> $_ = "<var>StmtBal,7,60,19</var>";
>
> /^\<(\w+)>(\w+),(\d+),(\d+),(\d+)/
>
> The above works fine for "<var>StmtBal,7,60,19</var>". I get the following:
>
> var
> StmtBal
> 7
> 60
> 19
>
> But not for "<var>Acct#,5,0,1</var>" or
> "<var>.........Description..........,30,16,6</var>".
>
> How do I handle the "#", "*" etc and ".."?
Maybe you could split on ','.
if( m{^<var>(.*)</var>$} )
{
my @vals = split /,/, $1;
print join("\n", @vals, '');
}
------------------------------
Date: Tue, 23 Jan 2007 14:14:13 -0600
From: "Mumia W. (NOSPAM)" <paduille.4060.mumia.w+nospam@earthlink.net>
Subject: Re: missing simple regex
Message-Id: <ep5qk8$nuv$2@aioe.org>
On 01/23/2007 01:36 PM, Jerry wrote:
> I am reading lines from a file that I need to breakdown.
>
> (yes, using strick)
>
> $_ = "<var>StmtBal,7,60,19</var>";
>
> /^\<(\w+)>(\w+),(\d+),(\d+),(\d+)/
> [...]
/^\<(\w+)>([\w.#]+),(\d+),(\d+),(\d+)/
--
Windows Vista and your freedom in conflict:
http://www.securityfocus.com/columnists/420/2
------------------------------
Date: Tue, 23 Jan 2007 21:53:58 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: missing simple regex
Message-Id: <9dtcr2h5jfgb4i65t6thm2epe6lkobuj5s@4ax.com>
On Tue, 23 Jan 2007 13:36:27 -0600, "Jerry"
<jpreston@general-steel.com> wrote:
> /^\<(\w+)>(\w+),(\d+),(\d+),(\d+)/
>
>The above works fine for "<var>StmtBal,7,60,19</var>". I get the following:
[snip]
>But not for "<var>Acct#,5,0,1</var>" or
>"<var>.........Description..........,30,16,6</var>".
>
>How do I handle the "#", "*" etc and ".."?
Well, you could use charachter classes, e.g. [\w#.], but wouldn't it
be easier to split on /,/?
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 23 Jan 2007 20:57:27 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: missing simple regex
Message-Id: <slrnerctlg.msb.abigail@alexandra.abigail.be>
Jerry (jpreston@general-steel.com) wrote on MMMMDCCCXCIII September
MCMXCIII in <URL:news:12rcotu7ckk1ef1@corp.supernews.com>:
`' I am reading lines from a file that I need to breakdown.
`'
`' (yes, using strick)
`'
`' $_ = "<var>StmtBal,7,60,19</var>";
`'
`' /^\<(\w+)>(\w+),(\d+),(\d+),(\d+)/
`'
`' The above works fine for "<var>StmtBal,7,60,19</var>". I get the following:
`'
`' var
`' StmtBal
`' 7
`' 60
`' 19
`'
`' But not for "<var>Acct#,5,0,1</var>" or
`' "<var>.........Description..........,30,16,6</var>".
`'
`' How do I handle the "#", "*" etc and ".."?
Hmmm. The problem with this sort of questions is that it's not well
defined what you want. You're showing two examples, but it's clear
from the description there's more to it. But what? "etc" is very hard
to translate into a regexp.
Abigail
--
#!/opt/perl/bin/perl -w
$\ = $"; $SIG {TERM} = sub {print and exit};
kill 15 => fork for qw /Just another Perl Hacker/;
------------------------------
Date: 23 Jan 2007 03:05:15 -0800
From: "vabby" <vaibhav.aparimit@gmail.com>
Subject: passing parameters to a perl prgram using getopts
Message-Id: <1169550315.439649.305700@l53g2000cwa.googlegroups.com>
Hi
I have to pass certain parameters to a perl program like if log file is
required or not, wot process is to be setup and the mode. I ahve
written the following script, named bat.pl
use Getopt::Std;
use vars qw($opt_p $opt_m $opt_l);
getopts("p:m:l");
my $process = uc($opt_p) || usage();
my $mode = uc($opt_m) || usage();
my $logging = uc($opt_l) ;
print "\n the value of process is $process\n";
print "\n the value of mode is $mode\n";
print "\n the value of log is $logging\n";
exit(1);
so i invoke the program this way
bat -p Ipc -m qa -l N
my problem is that, whatever the value of the 3rd parameter I pass,
the $logging variable gets the value of 1. This is again true if a
reduce the number of variables to be passed to 2 , then the last
variable again gets the value of 1, irrespective of whatever I pass.
------------------------------
Date: 23 Jan 2007 03:05:42 -0800
From: "vabby" <vaibhav.aparimit@gmail.com>
Subject: passing parameters to a perl prgram using getopts
Message-Id: <1169550342.537166.131630@a75g2000cwd.googlegroups.com>
Hi
I have to pass certain parameters to a perl program like if log file is
required or not, wot process is to be setup and the mode. I ahve
written the following script, named bat.pl
use Getopt::Std;
use vars qw($opt_p $opt_m $opt_l);
getopts("p:m:l");
my $process = uc($opt_p) || usage();
my $mode = uc($opt_m) || usage();
my $logging = uc($opt_l) ;
print "\n the value of process is $process\n";
print "\n the value of mode is $mode\n";
print "\n the value of log is $logging\n";
exit(1);
so i invoke the program this way
bat -p Ipc -m qa -l N
my problem is that, whatever the value of the 3rd parameter I pass,
the $logging variable gets the value of 1. This is again true if a
reduce the number of variables to be passed to 2 , then the last
variable again gets the value of 1, irrespective of whatever I pass.
tx
vabby
------------------------------
Date: 23 Jan 2007 11:15:48 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: passing parameters to a perl prgram using getopts
Message-Id: <51m934F1kt6eqU1@mid.dfncis.de>
vabby <vaibhav.aparimit@gmail.com> wrote in comp.lang.perl.misc:
> Hi
> I have to pass certain parameters to a perl program like if log file is
> required or not, wot process is to be setup and the mode. I ahve
> written the following script, named bat.pl
> use Getopt::Std;
>
> use vars qw($opt_p $opt_m $opt_l);
> getopts("p:m:l");
You can avoid the use of package variables if you give getopts()
a lexical hash to work with:
getopts( "p:m:l", \ my %opt);
The option letters and their values become the keys and values of the
hash.
> my $process = uc($opt_p) || usage();
So this would become
my $process = uc( $opt{ p}) || usage();
etc...
> my $mode = uc($opt_m) || usage();
> my $logging = uc($opt_l) ;
> print "\n the value of process is $process\n";
> print "\n the value of mode is $mode\n";
> print "\n the value of log is $logging\n";
> exit(1);
>
> so i invoke the program this way
> bat -p Ipc -m qa -l N
>
>
> my problem is that, whatever the value of the 3rd parameter I pass,
> the $logging variable gets the value of 1. This is again true if a
> reduce the number of variables to be passed to 2 , then the last
> variable again gets the value of 1, irrespective of whatever I pass.
Sure. The "l" key doesn't take a value, "p" and "m" do. Re-read perldoc
Getopt::Std to see why.
Anno
------------------------------
Date: 23 Jan 2007 03:29:15 -0800
From: "vabby" <vaibhav.aparimit@gmail.com>
Subject: Re: passing parameters to a perl prgram using getopts
Message-Id: <1169551755.139834.153090@j27g2000cwj.googlegroups.com>
Was going thru the perldoc, and this is what they had to say:
"For each switch found, sets $opt_x (where x is the switch name) to the
value of the argument if an argument is expected, or 1 otherwise."
I dont understand. can u plz explain, why is the last switch geting the
value of 1.
tx
vabby
------------------------------
Date: 23 Jan 2007 03:32:47 -0800
From: "vabby" <vaibhav.aparimit@gmail.com>
Subject: Re: passing parameters to a perl prgram using getopts
Message-Id: <1169551967.253341.234270@d71g2000cwa.googlegroups.com>
okay got it. tx for the help
------------------------------
Date: 23 Jan 2007 13:55:31 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: passing parameters to a perl prgram using getopts
Message-Id: <slrnerc4uj.p7u.glennj@smeagol.ncf.ca>
At 2007-01-23 06:05AM, "vabby" wrote:
> Hi
> I have to pass certain parameters to a perl program like if log file is
> required or not, wot process is to be setup and the mode. I ahve
> written the following script, named bat.pl
> use Getopt::Std;
>
> use vars qw($opt_p $opt_m $opt_l);
> getopts("p:m:l");
-------------^^
"-l" is a boolean option (there's no trailing colon). It's set to 1 if
present, 0 otherwise.
> my $logging = uc($opt_l) ;
Use of uc is irrelevant here: $opt_l is an integer.
> so i invoke the program this way
> bat -p Ipc -m qa -l N
The parameter "N" is not related to "-l" in any way -- $ARGV[0] == "N"
> my problem is that, whatever the value of the 3rd parameter I pass,
> the $logging variable gets the value of 1. This is again true if a
> reduce the number of variables to be passed to 2 , then the last
> variable again gets the value of 1, irrespective of whatever I pass.
Presumably, you always pass -l as the last parameter.
--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry
------------------------------
Date: Tue, 23 Jan 2007 19:47:41 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Pattern Matching and Extraction
Message-Id: <iulcr25it48ijimv9d717njsqg7pngmaqt@4ax.com>
On 22 Jan 2007 15:16:21 -0800, "doni" <doni.sekar@gmail.com> wrote:
>thanks a lot Michele, I was able to get the result I wanted using your
>method.
Just bear in mind that although it may have worked in this particular
case, due to the unreliability of your "format", "my" method will also
be unreliable.
>Michele Dondi wrote:
[snip full quoted content]
*Please* do not top-post!
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 23 Jan 2007 12:09:23 -0800
From: "doni" <doni.sekar@gmail.com>
Subject: Re: Pattern Matching and Extraction
Message-Id: <1169582963.116680.37610@q2g2000cwa.googlegroups.com>
> If you do not know what "top post" means, then you should try to find
> out as soon as possible.
thanks, tad for pointing it out to me...
doni.
------------------------------
Date: Tue, 23 Jan 2007 10:17:06 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: perl regexp question
Message-Id: <230120071017068914%jgibson@mail.arc.nasa.gov>
In article <1169523240.569007.119630@11g2000cwr.googlegroups.com>,
IcyMint <carlston88@gmail.com> wrote:
> Hi, I'm trying to change the contents of a file base on the substitute
> list from the other file. I'd copied my progress over here, albeit with
> some changes. The content file format is: #name group OR #name \n+
> group
Is the '+' at the end of this line a real symbol or a metasymbol?
> The script is working fine, but I want it to compare if the group name
> is correct. If it is incorrect, change it, and count how many times it
> had been changed. What I'm trying to do is something like:
> while ($content =~ /\n\#(\S+)\b\s+(\S+)/g) {
> my($name,$group) = ($1,$2);
> unless ($group eq $data{$name}) {
> $2 = $data{$name};
> $count{$name}++;
> }
> }
> It's not a valid code, it gave me errors, but i'm just including it so
> that maybe you'll understand what I'm trying to achieve. Can you help
> me with this? Thank you!
>
>
use strict;
use warnings;
> open(FILE,"content.txt") or die "Cannot open file content.txt~ $!\n";
> open(DATA,"data.txt") or die "Cannot open file data.txt~ $!\n";
>
> undef $/;
> my $content = <FILE>;
Localize your change to a global variable:
my $content = do{ local $/; <FILE>};
> my $data = <DATA>;
>
> while ($data =~ /\nsubstitute\s+(\S+)\s+(\S+)/g) {
> $data{$1} = $2;
> }
You are ignoring the substitution on the first line of the file, so you
need a blank line at the beginning of the file. Better is to use the \G
metasymbol and m modifier. Even simpler and better is to read the file
one line at a time and extract the substitution strings from a single
line one-at-a-time:
my %data;
while (<DATA>) {
if( m{ \A \s* substitute \s+ (\S+) \s+ (\S+) }x ) {
$data{$1} = $2;
}
}
>
> foreach my $key (keys %data) {
> $content =~ s/\n\#$key\b\s*\S+/\n\#$key $data{$key}/g;
You say you are trying to modify group names, which you say is located
in the second field of the content line. Yet is appears you are looking
for the group name in the FIRST field of the content line. Which is it?
You will also fail to substitute in the first line of the data unless
you use the ^ or \A metasymbols and the 'm' modifier.
> $content =~ s/\n\#$key\b\s*\n\+\s+\S+/\n\#$key\n\+\s$data{$key}/g;
You cannot use \s in a replacement string. Had you put 'use warnings:'
at the beginning of your program, Perl would have told you that.
It is simpler to just capture the non-changing parts of the original
strings:
$content =~ s/^(\s*\#\S+\s+)$key/$1$data{$key}/mg;
$content =~ s/^(\#\S+\s*\n\+\s+)$key/$1$data{$key}/mg;
> }
>
>
> The content.txt(modified version) file looks something like this:
>
> #benjamin TB3
> #desmond TG2
> #terrence TE1
> #abigail_lim_suet_ching
> + KR8
>
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
------------------------------
Date: 23 Jan 2007 12:25:26 -0800
From: "doni" <doni.sekar@gmail.com>
Subject: Statistics Extraction
Message-Id: <1169583926.392340.287500@s48g2000cws.googlegroups.com>
Hi,
I wanted to extract specific information of MAC and PHY statistics from
the statistics log file. The Statistics file contains information other
than MAC and PHY also.
I am mainly concerned about "frames with invalid header" and "packets
with invalid length" from the MAC Statistics and "transmit errors" from
PHY Statistics.
Can anyone let me know how can I extract this information.
Here is a snapshot of the Statistics file that gets generated.
MAC statistics:
0 frames with invalid header
546 confirmed frames sent succesfully
1693 confirmed frames sent unsuccesfully
542 confirmed frames received
4597 total frames received
851 data packets received
549 packets sent successfully
152 packets sent unsuccessfully
763 packets queued by network layer
61 packet transmissions timed out
0 packets with invalid length
0 out of order fragments received
87 duplicate fragments received
0 partial packets received
4 packet reassemblies timed out
0 no buffers
PHY statistics:
3404 frames transmitted
105 transmits aborted due to rx
0 transmit errors
0 late transmits
11 tx buffer loads interrupted
0 tx buffer load failures
4598 receive interrupts
4598 frames received
0 received frames lost
0 zero length frames received
0 receive cmd errors
Network statistics:
851 total packets received
0 bad packet length
0 bad version number
0 outgoing packets with no route
0 input packets with bad destination address
0 input packets from wrong channel
0 packets dropped for exceeding TTL
0 packets dropped due to full socket buffers
0 packets dropped due to no receiver
0 packets dropped due to running out of memory
762 total packets sent
549 packets succesfully transmitted
213 packets sent unsuccessfully
Thanks,
doni
------------------------------
Date: Tue, 23 Jan 2007 21:58:12 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Statistics Extraction
Message-Id: <2htcr2pk6q5c5pkuo2adgtkm0b3f6r4fbd@4ax.com>
On 23 Jan 2007 12:25:26 -0800, "doni" <doni.sekar@gmail.com> wrote:
>I am mainly concerned about "frames with invalid header" and "packets
>with invalid length" from the MAC Statistics and "transmit errors" from
>PHY Statistics.
>Can anyone let me know how can I extract this information.
>
>Here is a snapshot of the Statistics file that gets generated.
[snip]
>MAC statistics:
> 0 frames with invalid header
What have you tried thus far? In any case you may try some regexen
like
/(\d+)\s+frames with invalid header/
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 23 Jan 2007 13:33:10 -0800
From: "doni" <doni.sekar@gmail.com>
Subject: Re: Statistics Extraction
Message-Id: <1169587990.541501.306540@d71g2000cwa.googlegroups.com>
Michele Dondi wrote:
> What have you tried thus far? In any case you may try some regexen
> like
>
> /(\d+)\s+frames with invalid header/
>
I was trying to do something other than regexp so that If I need
multiple searches, I can easily incorporate them.
I didnt have much success till now...
#! /usr/bin/perl
use strict;
use warnings;
my $ex_data = 'netstat.log';
open (NETSTAT,$ex_data) || die("Cannot Open File: $!");
### Prompt the User for Input ###
print "Enter the stats(MAC or PHY) information that need to be
extracted:";
my $input = <STDIN>;
chomp($input);
print $input;
foreach $line(<NETSTAT>) {
chomp $line;
if ($input =~ m/^$line/i) {
print "We are going to extract RF MAC Statistics\n";
}
}
close(NETSTAT) || die("Cannot close $ex_data: $!");
------------------------------
Date: 23 Jan 2007 14:22:27 -0800
From: "DJ Stunks" <DJStunks@gmail.com>
Subject: Re: Statistics Extraction
Message-Id: <1169590947.605316.287890@v45g2000cwv.googlegroups.com>
doni wrote:
> Michele Dondi wrote:
>
> > What have you tried thus far? In any case you may try some regexen
> > like
> >
> > /(\d+)\s+frames with invalid header/
> >
>
> I was trying to do something other than regexp so that If I need
> multiple searches, I can easily incorporate them.
> I didnt have much success till now...
#!/usr/bin/perl
use strict;
use warnings;
my (%statistics, $type);
while ( my $line = <DATA> ) {
if ( $line =~ m{^ (\S+) }x ) {
$type = $1;
}
elsif ( $line =~ m{ (\d+) \s+ (.+?) \s* $}mx ) {
$statistics{ $type }{ $2 } = $1;
}
}
print "MAC stats for 'frames with invalid header': ",
$statistics{ MAC }{ 'frames with invalid header' },
"\n";
__DATA__
MAC statistics:
0 frames with invalid header
546 confirmed frames sent succesfully
1693 confirmed frames sent unsuccesfully
542 confirmed frames received
4597 total frames received
851 data packets received
549 packets sent successfully
152 packets sent unsuccessfully
763 packets queued by network layer
61 packet transmissions timed out
0 packets with invalid length
0 out of order fragments received
87 duplicate fragments received
0 partial packets received
4 packet reassemblies timed out
0 no buffers
PHY statistics:
3404 frames transmitted
105 transmits aborted due to rx
0 transmit errors
0 late transmits
11 tx buffer loads interrupted
0 tx buffer load failures
4598 receive interrupts
4598 frames received
0 received frames lost
0 zero length frames received
0 receive cmd errors
Network statistics:
851 total packets received
0 bad packet length
0 bad version number
0 outgoing packets with no route
0 input packets with bad destination address
0 input packets from wrong channel
0 packets dropped for exceeding TTL
0 packets dropped due to full socket buffers
0 packets dropped due to no receiver
0 packets dropped due to running out of memory
762 total packets sent
549 packets succesfully transmitted
213 packets sent unsuccessfully
-jp
------------------------------
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 V11 Issue 66
*************************************