[30098] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1341 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 7 18:09:43 2008

Date: Fri, 7 Mar 2008 15:09:08 -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           Fri, 7 Mar 2008     Volume: 11 Number: 1341

Today's topics:
        [OT] Re: Rename File Using Strring Found in File? <m@rtij.nl.invlalid>
        a better code by foreach? <rose@russ.org>
    Re: a better code by foreach? <ben@morrow.me.uk>
    Re: a better code by foreach? xhoster@gmail.com
    Re: a better code by foreach? <tzz@lifelogs.com>
    Re: FAQ 5.3 How do I count the number of lines in a fil <brian.d.foy@gmail.com>
    Re: FAQ 5.3 How do I count the number of lines in a fil <jm@nospam.fr>
        Grabbing GPS data using perl <deadpickle@gmail.com>
    Re: Grabbing GPS data using perl <jimsgibson@gmail.com>
    Re: grep in file and date process <joe@inwap.com>
    Re: Outlook -- email <syscjm@sumire.gwu.edu>
        Question on regex cyrusgreats@gmail.com
    Re: Question on regex <noreply@gunnar.cc>
    Re: Question on regex cyrusgreats@gmail.com
    Re: Question on regex <willem@stack.nl>
    Re: Question on regex <glex_no-spam@qwest-spam-no.invalid>
    Re: Question on regex <jimsgibson@gmail.com>
    Re: Question on regex cyrusgreats@gmail.com
    Re: Question on regex cyrusgreats@gmail.com
    Re: Question on regex <pgovern@u.washington.edu>
    Re: Question on regex <jimsgibson@gmail.com>
    Re: Question on regex <m@rtij.nl.invlalid>
    Re: regexp for s/// <noreply@gunnar.cc>
    Re: Rename File Using Strring Found in File? <joe@inwap.com>
    Re: Rename File Using Strring Found in File? <abigail@abigail.be>
    Re: sample client server socket issue <jimsgibson@gmail.com>
    Re: sample client server socket issue <jm@nospam.fr>
    Re: Sending using Net::IRC <bik.mido@tiscalinet.it>
    Re: Using Perl to get data from website <ben@morrow.me.uk>
    Re: Using Perl to get data from website <fiazidris@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Fri, 7 Mar 2008 23:01:15 +0100
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: [OT] Re: Rename File Using Strring Found in File?
Message-Id: <pan.2008.03.07.22.01.15@rtij.nl.invlalid>

On Fri, 07 Mar 2008 14:11:53 +0000, Abigail wrote:

> _
> Ben Morrow (ben@morrow.me.uk) wrote on VCCXCIX September MCMXCIII in
> <URL:news:o590a5-pj5.ln1@osiris.mauzo.dyndns.org>: ..
> ..
> ..  Perl is *never* installed as /bin/perl.
> 
> 
> Bullocks.
> 
> Even beside the fact Perl will install itself pretty much everywhere
> where the person running Configure tells it to (barring existance of the
> directory and permission), there's a major operating system where /bin
> and /usr/bin are identical.

Which reminds of the time I wanted to move /usr. Should be a static 
filesystem, so create new slice, copy contents, mv /usr /usr.old and then 
just ...... boot from CD to fix the mess.

M4


------------------------------

Date: Fri, 7 Mar 2008 21:50:54 +0800
From: "Rose" <rose@russ.org>
Subject: a better code by foreach?
Message-Id: <fqrh80$j18$1@ijustice.itsc.cuhk.edu.hk>

Is it possible for me to use "foreach" to make the following codes in a 
better way? I don't want to create subroutine and call. Because I can't use 
@%arr this time (%arr1 not equal to %arr[1]). Copying the %arr1, %arr2, ..., 
%arrn into a single large array is impractical, because %arr1, ...n is 
already very large each.


while (($loc, $sub) = each(%arr1)) {
  print "$loc\tSub\t$sub\t$notes[0]\t$start\t$end\n";
}

while (($loc, $sub) = each(%arr2)) {
  print "$loc\tSub\t$sub\t$notes[0]\t$start\t$end\n";
}

 ...

while (($loc, $sub) = each(%arrn)) {
  print "$loc\tSub\t$sub\t$notes[0]\t$start\t$end\n";
}




------------------------------

Date: Fri, 7 Mar 2008 14:55:00 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: a better code by foreach?
Message-Id: <4j18a5-n65.ln1@osiris.mauzo.dyndns.org>


Quoth "Rose" <rose@russ.org>:
> Is it possible for me to use "foreach" to make the following codes in a 
> better way? I don't want to create subroutine and call. Because I can't use 
> @%arr this time (%arr1 not equal to %arr[1]). Copying the %arr1, %arr2, ..., 
> %arrn into a single large array is impractical, because %arr1, ...n is 
> already very large each.
> 
> while (($loc, $sub) = each(%arr1)) {
>   print "$loc\tSub\t$sub\t$notes[0]\t$start\t$end\n";
> }

Making an array out of several hashrefs doesn't copy the contents, so
you can perfectly well just do

    my @arr = (\%arr1, \%arr2, ...);

and perl will only allocate a small (proportional to the number of
hashes, not to the size of their contents) amount of memory.

However, you are going about this the wrong way. Whenever you have
variables named like that, it is a hint you should have used an array to
start with. Go back to the code that populates %arrn, and change it to
use %{$arr[n]} instead. Chances are you can rewrite it to use for loops
in a similar way. Then you can do

    foreach my $hash (@arr) {
        while (my ($loc, $sub) = each %$hash) {
            ...
        }
    }

You are using 'strict', aren't you?

Ben



------------------------------

Date: 07 Mar 2008 15:08:52 GMT
From: xhoster@gmail.com
Subject: Re: a better code by foreach?
Message-Id: <20080307100853.668$09@newsreader.com>

"Rose" <rose@russ.org> wrote:
> Is it possible for me to use "foreach" to make the following codes in a
> better way? I don't want to create subroutine and call. Because I can't
> use @%arr this time (%arr1 not equal to %arr[1]).


Perhaps you have written something in some other thread that I haven't
read that if I had read would make the above make sense, but otherwise
the above doesn't make sense.

> Copying the %arr1,
> %arr2, ..., %arrn into a single large array is impractical, because
> %arr1, ...n is already very large each.

@arrn = \(%arr1, %arr2, %arr3, %arr4);

This just creates references to each hash.  The data in the hashes is not
copied, it just has two paths to get to it, through the old name and
through the new reference.  But it would better to just work with @arrn
from the start and never have %arr1 to start with.



>
> while (($loc, $sub) = each(%arr1)) {
>   print "$loc\tSub\t$sub\t$notes[0]\t$start\t$end\n";
> }
>
> while (($loc, $sub) = each(%arr2)) {
>   print "$loc\tSub\t$sub\t$notes[0]\t$start\t$end\n";
> }

foreach my $ref (@arrn) {
  while (($loc, $sub) = each(%$ref)) {
    print "$loc\tSub\t$sub\t$notes[0]\t$start\t$end\n";
  }
};



Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


------------------------------

Date: Fri, 07 Mar 2008 09:57:57 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: a better code by foreach?
Message-Id: <861w6my1a2.fsf@lifelogs.com>

On Fri, 7 Mar 2008 21:50:54 +0800 "Rose" <rose@russ.org> wrote: 

R> Is it possible for me to use "foreach" to make the following codes in a 
R> better way? I don't want to create subroutine and call. Because I can't use 
R> @%arr this time (%arr1 not equal to %arr[1]). Copying the %arr1, %arr2, ..., 
R> %arrn into a single large array is impractical, because %arr1, ...n is 
R> already very large each.


R> while (($loc, $sub) = each(%arr1)) {
R>   print "$loc\tSub\t$sub\t$notes[0]\t$start\t$end\n";
R> }

R> while (($loc, $sub) = each(%arr2)) {
R>   print "$loc\tSub\t$sub\t$notes[0]\t$start\t$end\n";
R> }

R> ...

R> while (($loc, $sub) = each(%arrn)) {
R>   print "$loc\tSub\t$sub\t$notes[0]\t$start\t$end\n";
R> }

Untested code.  I like printf() but the print() works fine too.  See
`perldoc perlref' for further information.

# you can automate this assignment too, but it may not make sense in
# your application's context
my @arrays = (\%arr1, \%arr2 ... \%arrn);

foreach my $array (@arrays)
{
 foreach my $loc (keys %$array)
 {
  printf "%s\tSub\t%s\t%s\t%s\t%s\n", 
   $loc, $array->{$loc}, $notes[0], $start, $end;
 }
}



------------------------------

Date: Fri, 07 Mar 2008 11:11:19 -0600
From: brian d  foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 5.3 How do I count the number of lines in a file?
Message-Id: <070320081111196950%brian.d.foy@gmail.com>

In article <47d06c07$0$21142$7a628cd7@news.club-internet.fr>, jm
<jm@nospam.fr> wrote:

> PerlFAQ Server a écrit :
> 
> > 5.3: How do I count the number of lines in a file?

> How does this code handle other unicode new line codages, such as 0x85,
> 0x0d 0x0a?

If you have a different idea of the human concept of "line", you'll
have to adjust the code to have the right line ending (and probably not
use tr///).


------------------------------

Date: Sat, 08 Mar 2008 00:01:14 +0100
From: jm <jm@nospam.fr>
Subject: Re: FAQ 5.3 How do I count the number of lines in a file?
Message-Id: <47d1c93a$0$21149$7a628cd7@news.club-internet.fr>

brian d foy a écrit :
> In article <47d06c07$0$21142$7a628cd7@news.club-internet.fr>, jm
> <jm@nospam.fr> wrote:
> 
>> PerlFAQ Server a écrit :
>>
>>> 5.3: How do I count the number of lines in a file?
> 
>> How does this code handle other unicode new line codages, such as 0x85,
>> 0x0d 0x0a?
> 
> If you have a different idea of the human concept of "line", you'll
> have to adjust the code to have the right line ending (and probably not
> use tr///).

I do not remember where I read it, but
specificity of computers standards is there are so many.


I assume the following can be used:

«A newline sequence is defined to be any of the following:

\u000A | \u000B | \u000C | \u000D | \u0085 | \u2028 | \u2029 |
\u000D\u000A »

This regular expression comes from:

http://www.unicode.org/unicode/reports/tr18/
Unicode Technical Standard #18
Unicode Regular Expressions

http://unicode.org/reports/tr13/tr13-9.html
Unicode Standard Annex #13
Unicode Newline Guidelines




However it is not always true, because with some encodings (cp850 for
instance), 0x85 is plain character.



PS: If I understand well, there is also a report which allow to
automagically display newlines when necessary according to
opportunities... but this is another issue.
http://www.unicode.org/reports/tr14/
Unicode Standard Annex #14
Line Breaking Properties


------------------------------

Date: Fri, 7 Mar 2008 13:48:22 -0800 (PST)
From: deadpickle <deadpickle@gmail.com>
Subject: Grabbing GPS data using perl
Message-Id: <3d82b907-851e-4dd0-ba60-a6f5faed5efc@u72g2000hsf.googlegroups.com>

I have been using the perl module perl-GPS to grab data from a DeLorme
(NMEA) GPS device though I am having some problems with this module.
The first thing is that the module is blocking when it grabs data. the
second is that the location is off by a lot.I have emailed the creator
but what I am wondering is if there are other GPS perl module that I
can use to get GPS data from a COM port or USB?


------------------------------

Date: Fri, 07 Mar 2008 14:22:28 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: Grabbing GPS data using perl
Message-Id: <070320081422288642%jimsgibson@gmail.com>

In article
<3d82b907-851e-4dd0-ba60-a6f5faed5efc@u72g2000hsf.googlegroups.com>,
deadpickle <deadpickle@gmail.com> wrote:

> I have been using the perl module perl-GPS to grab data from a DeLorme
> (NMEA) GPS device though I am having some problems with this module.
> The first thing is that the module is blocking when it grabs data. the
> second is that the location is off by a lot.I have emailed the creator
> but what I am wondering is if there are other GPS perl module that I
> can use to get GPS data from a COM port or USB?

A search on "GPS" at <http://search.cpan.org> produces 90 hits,
including the possibly relevant GPS::NMEA (I have not used it).

-- 
Jim Gibson

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


------------------------------

Date: Fri, 07 Mar 2008 05:35:02 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: grep in file and date process
Message-Id: <fbSdnZ2gTeYV2UzanZ2dnUVZ_oSunZ2d@comcast.com>

Mr_Noob wrote:
> my @clientlog;
> while(<FILE>) {
> 	next unless /put \/$client/;
> 	push (@clientlog, $_);
> }

Have you considered using a hash instead of an array?

my %clientlog;
while (<FILE>) {
   $clientlog{$2} = $1 if m%(.*) put /(name_of_client.*?)/%;
}
print "$_ = $clientlog{$_}\n" for sort keys %clientlog;


	-Joe


------------------------------

Date: Fri, 07 Mar 2008 20:48:10 -0000
From: Chris Mattern <syscjm@sumire.gwu.edu>
Subject: Re: Outlook -- email
Message-Id: <slrnft3ag7.6uq.syscjm@sumire.gwu.edu>

On 2008-03-07, cmiller@directv.com <cmiller@directv.com> wrote:
> For anyone looking for a way around the Outlook pop up security box,
> there is a program called ClickYes that can be installed which will
> solve the problem. It will reside on your task bar and deal with the
> pop-up window. Hope this helps.

Yes, now you too can get your Windows box infected 50% faster by
disposing of those pesky security dialogs!


-- 
             Christopher Mattern

NOTICE
Thank you for noticing this new notice
Your noticing it has been noted
And will be reported to the authorities


------------------------------

Date: Fri, 7 Mar 2008 13:17:45 -0800 (PST)
From: cyrusgreats@gmail.com
Subject: Question on regex
Message-Id: <0658d355-4bc6-486e-8cae-51cddf8d19e1@d4g2000prg.googlegroups.com>

I'm using the following regex using perl to get anything that is not
0.0 but it doesn't work the way I want it, I need to print those that
are not 0.0

The string is:

 0.0 19968 admin    /bin/bash -l
 1.0 20037 admin    /bin/bash -l
 0.2 20085 admin    /bin/bash -l
 0.0 20363 admin    /bin/bash -l

next if $line =~ /^\s0.0/;     # skip 0.0
print $line, "\n";

the out put is:
next if $line =~ /^\s0.0/;     # skip 0.0

But I all I want is:

1.0 20037 admin    /bin/bash -l
 0.2 20085 admin    /bin/bash -l

Anyone out there know how to fix this one?
Thanks in advance..


------------------------------

Date: Fri, 07 Mar 2008 22:38:17 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Question on regex
Message-Id: <63dr2tF27d6toU1@mid.individual.net>

cyrusgreats@gmail.com wrote:
> I'm using the following regex using perl to get anything that is not
> 0.0 but it doesn't work the way I want it, I need to print those that
> are not 0.0
> 
> The string is:
> 
>  0.0 19968 admin    /bin/bash -l
>  1.0 20037 admin    /bin/bash -l
>  0.2 20085 admin    /bin/bash -l
>  0.0 20363 admin    /bin/bash -l
> 
> next if $line =~ /^\s0.0/;     # skip 0.0
> print $line, "\n";
> 
> the out put is:
> next if $line =~ /^\s0.0/;     # skip 0.0
> 
> But I all I want is:
> 
> 1.0 20037 admin    /bin/bash -l
>  0.2 20085 admin    /bin/bash -l

Please post a short but complete program to show us what you are doing, 
as is suggested in the posting guidelines for this group: 
http://www.rehabitation.com/clpmisc/clpmisc_guidelines.html

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


------------------------------

Date: Fri, 7 Mar 2008 13:50:29 -0800 (PST)
From: cyrusgreats@gmail.com
Subject: Re: Question on regex
Message-Id: <94bc3300-c6d3-450d-8a91-8bf8d992065e@u10g2000prn.googlegroups.com>

> Please post a short but complete program to show us what you are doing,
> as is suggested in the posting guidelines for this group:http://www.rehabitation.com/clpmisc/clpmisc_guidelines.html
>
> --
> Gunnar Hjalmarsson
> Email:http://www.gunnar.cc/cgi-bin/contact.pl
Well that depends of the question, the question is very straight
forward, anyway here is portion of the code..again thanks..

my $cmd = "ps -eo pcpu,pid,user,args";
my @output = '$cmd';
foreach my $line (@output) {
  next if $line =~ /\s0.0/;     # skip 0.0
  print $line, "\n";
}



------------------------------

Date: Fri, 7 Mar 2008 22:07:32 +0000 (UTC)
From: Willem <willem@stack.nl>
Subject: Re: Question on regex
Message-Id: <slrnft3f54.2qb5.willem@snail.stack.nl>

cyrusgreats@gmail.com wrote:
)> Please post a short but complete program to show us what you are doing,
)> as is suggested in the posting guidelines for this group:http://www.rehabitation.com/clpmisc/clpmisc_guidelines.html
)>
)> --
)> Gunnar Hjalmarsson
)> Email:http://www.gunnar.cc/cgi-bin/contact.pl
) Well that depends of the question, the question is very straight
) forward, anyway here is portion of the code..again thanks..
)
) my $cmd = "ps -eo pcpu,pid,user,args";
) my @output = '$cmd';
) foreach my $line (@output) {
)   next if $line =~ /\s0.0/;     # skip 0.0
)   print $line, "\n";
) }

First:  The dot matches any character in a regexp.
Second: I don't see the caret at the start of the regexp to anchor it.
        This will probably result in spurious matches.
Third:  The lines will already have newlines on them so the extra one
        in the print statement will produce blank lines.

Oh, and fourth: in the original question, I *did* see the caret at the
start, which made the question impossible to answer as such, let alone
straight forward.  This is one reason why the best way is to copy-paste
the relevant bits of your code.  All characters count.


SaSW, Willem
-- 
Disclaimer: I am in no way responsible for any of the statements
            made in the above text. For all I know I might be
            drugged or something..
            No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT


------------------------------

Date: Fri, 07 Mar 2008 16:08:15 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Question on regex
Message-Id: <47d1bcd0$0$89865$815e3792@news.qwest.net>

cyrusgreats@gmail.com wrote:
>> Please post a short but complete program to show us what you are doing,
>> as is suggested in the posting guidelines for this group:http://www.rehabitation.com/clpmisc/clpmisc_guidelines.html
>>
>> --
>> Gunnar Hjalmarsson
>> Email:http://www.gunnar.cc/cgi-bin/contact.pl
> Well that depends of the question, the question is very straight
> forward, anyway here is portion of the code..again thanks..
> 
> my $cmd = "ps -eo pcpu,pid,user,args";
> my @output = '$cmd';
> foreach my $line (@output) {
>   next if $line =~ /\s0.0/;     # skip 0.0
>   print $line, "\n";
> }
> 

Hu.. it seems to work just fine.

That prints:

$cmd

which doesn't match your pattern.

Maybe you want:

my @output = `$cmd`;

and

next if $line =~ /^\s0\.0/;


------------------------------

Date: Fri, 07 Mar 2008 14:15:39 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: Question on regex
Message-Id: <070320081415394112%jimsgibson@gmail.com>

In article
<94bc3300-c6d3-450d-8a91-8bf8d992065e@u10g2000prn.googlegroups.com>,
<cyrusgreats@gmail.com> wrote:

> > Please post a short but complete program to show us what you are doing,
> > as is suggested in the posting guidelines for this
> > group:http://www.rehabitation.com/clpmisc/clpmisc_guidelines.html
> >
> > --
> > Gunnar Hjalmarsson
> > Email:http://www.gunnar.cc/cgi-bin/contact.pl

> Well that depends of the question, the question is very straight
> forward, 

The question ("Anyone out there know how to fix this one?") is not at
all straight-forward unless you include a precise description of what
"this one" is. Your description included the following statements:

> I'm using the following regex using perl to get anything that is not
> 0.0 but it doesn't work the way I want it, I need to print those that
> are not 0.0
> 
> The string is:
> 
>  0.0 19968 admin    /bin/bash -l
>  1.0 20037 admin    /bin/bash -l
>  0.2 20085 admin    /bin/bash -l
>  0.0 20363 admin    /bin/bash -l
> 
> next if $line =~ /^\s0.0/;     # skip 0.0
> print $line, "\n";
> 
> the out put is:
> next if $line =~ /^\s0.0/;     # skip 0.0
> 
> But I all I want is:
> 
> 1.0 20037 admin    /bin/bash -l
>  0.2 20085 admin    /bin/bash -l

You seem to be saying that your Perl program is printing one of its own
statements, which is remarkable, if true.

> anyway here is portion of the code..again thanks..
> 
> my $cmd = "ps -eo pcpu,pid,user,args";
> my @output = '$cmd';
> foreach my $line (@output) {
>   next if $line =~ /\s0.0/;     # skip 0.0
>   print $line, "\n";
> }
> 

That code works on my system. What output do you get on your system?

To avoid false positives, you might want to use the following regex
instead:

  next if $line =~ m{ \A \s* 0\.0 }x;

-- 
Jim Gibson

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


------------------------------

Date: Fri, 7 Mar 2008 14:19:49 -0800 (PST)
From: cyrusgreats@gmail.com
Subject: Re: Question on regex
Message-Id: <e26115d0-3bd8-41c0-8f3a-1a8c0ed58ba1@d21g2000prf.googlegroups.com>

On Mar 7, 2:07 pm, Willem <wil...@stack.nl> wrote:
> cyrusgre...@gmail.com wrote:
>
> )> Please post a short but complete program to show us what you are doing,
> )> as is suggested in the posting guidelines for this group:http://www.rehabitation.com/clpmisc/clpmisc_guidelines.html
> )>
> )> --
> )> Gunnar Hjalmarsson
> )> Email:http://www.gunnar.cc/cgi-bin/contact.pl
> ) Well that depends of the question, the question is very straight
> ) forward, anyway here is portion of the code..again thanks..
> )
> ) my $cmd = "ps -eo pcpu,pid,user,args";
> ) my @output = '$cmd';
> ) foreach my $line (@output) {
> )   next if $line =~ /\s0.0/;     # skip 0.0
> )   print $line, "\n";
> ) }
>
> First:  The dot matches any character in a regexp.
> Second: I don't see the caret at the start of the regexp to anchor it.
>         This will probably result in spurious matches.
> Third:  The lines will already have newlines on them so the extra one
>         in the print statement will produce blank lines.
>
> Oh, and fourth: in the original question, I *did* see the caret at the
> start, which made the question impossible to answer as such, let alone
> straight forward.  This is one reason why the best way is to copy-paste
> the relevant bits of your code.  All characters count.
>
> SaSW, Willem
> --
> Disclaimer: I am in no way responsible for any of the statements
>             made in the above text. For all I know I might be
>             drugged or something..
>             No I'm not paranoid. You all think I'm paranoid, don't you !
> #EOT

ok, how about this, what if and only if I want to match anything but
not 0.0, since the above doesn't work..if the string as follows, I'm
interested in 0.2 not 0.0.
space 0.0 somewords
space 0.2 somewords


------------------------------

Date: Fri, 7 Mar 2008 14:22:05 -0800 (PST)
From: cyrusgreats@gmail.com
Subject: Re: Question on regex
Message-Id: <78aeb51c-61e6-4ae3-9223-eb4378979569@e23g2000prf.googlegroups.com>


> That code works on my system. What output do you get on your system?
>
> To avoid false positives, you might want to use the following regex
> instead:
>
>   next if $line =~ m{ \A \s* 0\.0 }x;
>
> --
> Jim Gibson
>
>  Posted Via Usenet.com Premium Usenet Newsgroup Services
> ----------------------------------------------------------
>     ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
> ----------------------------------------------------------
>                http://www.usenet.com

I get all the lines as follows:
 0.0 19968 admin    /bin/bash -l
 1.0 20037 admin    /bin/bash -l
 0.2 20085 admin    /bin/bash -l
 0.0 20363 admin    /bin/bash -l


------------------------------

Date: Fri, 7 Mar 2008 14:56:00 -0800 (PST)
From: patrick <pgovern@u.washington.edu>
Subject: Re: Question on regex
Message-Id: <489b1fcf-e0e1-4791-a777-ea7921019c6f@e25g2000prg.googlegroups.com>

>my $cmd = "ps -eo pcpu,pid,user,args";

On AIX I get two leading spaces before the 0.0
On RHL I get only one space.

You can always change to ps -eo pcpu,pid,user,args | grep -v '^  0.0'

====>Patrick



------------------------------

Date: Fri, 07 Mar 2008 15:00:09 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: Question on regex
Message-Id: <070320081500096270%jimsgibson@gmail.com>

In article
<78aeb51c-61e6-4ae3-9223-eb4378979569@e23g2000prf.googlegroups.com>,
<cyrusgreats@gmail.com> wrote:

> > That code works on my system. What output do you get on your system?
> >
> > To avoid false positives, you might want to use the following regex
> > instead:
> >
> >   next if $line =~ m{ \A \s* 0\.0 }x;
> >
> > --
> > Jim Gibson
> >
> >  Posted Via Usenet.com Premium Usenet Newsgroup Services
> > ----------------------------------------------------------
> >     ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
> > ----------------------------------------------------------
> >                http://www.usenet.com
> 
> I get all the lines as follows:
>  0.0 19968 admin    /bin/bash -l
>  1.0 20037 admin    /bin/bash -l
>  0.2 20085 admin    /bin/bash -l
>  0.0 20363 admin    /bin/bash -l

I suggest you post your complete program and some sample data that you
cut-and-paste from your ps output. Use the <DATA> filehandle to read
the data, which you put at the end of your program after a line
containing only '__END__' or '__DATA__'.

Thanks.

-- 
Jim Gibson

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


------------------------------

Date: Sat, 8 Mar 2008 00:01:57 +0100
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: Question on regex
Message-Id: <pan.2008.03.07.23.01.57@rtij.nl.invlalid>

On Fri, 07 Mar 2008 14:19:49 -0800, cyrusgreats wrote:

> ok, how about this, what if and only if I want to match anything but not
> 0.0, since the above doesn't work..if the string as follows, I'm
> interested in 0.2 not 0.0.
> space 0.0 somewords
> space 0.2 somewords

You still don't get it. Your original code did match these lines. You say 
it did not work. That does not add up. We're not clairvoyant here, so we 
cannot determine what the problem really is. Post a small _but_complete_ 
program that shows your problem.

F.i.

#!/usr/bin/perl

use strict;
use warnings;

while (my $line = <DATA>) {
  next if $line =~ /^\s0.0/;     # skip 0.0
  print $line, "\n";
}

__DATA__
 0.0 19968 admin    /bin/bash -l
 1.0 20037 admin    /bin/bash -l
 0.2 20085 admin    /bin/bash -l
 0.0 20363 admin    /bin/bash -l

This outputs:

 1.0 20037 admin    /bin/bash -l

 0.2 20085 admin    /bin/bash -l

Which is exactly what I would expect. (Hint, you're missing a chomp 
somewhere).

HTH,
M4


------------------------------

Date: Fri, 07 Mar 2008 12:28:35 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: regexp for s///
Message-Id: <63cnbnF23b2buU1@mid.individual.net>

Frank Seitz wrote:
> Gunnar Hjalmarsson wrote:
>> Frank Seitz wrote:
>>> $myA //= ''
>>>
>>> is equivalent to 
>>>
>>> $myA = '' if !defined $myA;
>>
>>      $myA ||= '';
>>
>> works just as well, doesn't it?
> 
> $myA = 0;
> $myA ||= ''; # ups

Sure, but somehow I got the impression that the possible value (the OP 
gave us the example 'aaa') couldn't be 0. Only the OP can tell.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


------------------------------

Date: Fri, 07 Mar 2008 05:19:29 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: Rename File Using Strring Found in File?
Message-Id: <BdudnRgsZ_p_3UzanZ2dnUVZ_ufinZ2d@comcast.com>

Ben Morrow wrote:

>> #!/bin/perl
> 
> Perl is *never* installed as /bin/perl.

I beg to differ.

      linux# ln -s /usr/bin/perl /bin/perl

As to why I would want to do that, it means more useful information
from `ps ax` (when not using `ps axw`).

	-Joe


------------------------------

Date: 07 Mar 2008 14:11:53 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: Rename File Using Strring Found in File?
Message-Id: <slrnft2j99.ec.abigail@alexandra.abigail.be>

                                       _
Ben Morrow (ben@morrow.me.uk) wrote on VCCXCIX September MCMXCIII in
<URL:news:o590a5-pj5.ln1@osiris.mauzo.dyndns.org>:
 ..  
 ..  
 ..  Perl is *never* installed as /bin/perl.


Bullocks.

Even beside the fact Perl will install itself pretty much everywhere 
where the person running Configure tells it to (barring existance of
the directory and permission), there's a major operating system where
/bin and /usr/bin are identical.



Abigail
-- 
perl -wle 'sub _ "Just another Perl Hacker"; print prototype q ^_^'


------------------------------

Date: Fri, 07 Mar 2008 09:56:04 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: sample client server socket issue
Message-Id: <070320080956045923%jimsgibson@gmail.com>

In article <47d071a9$0$21144$7a628cd7@news.club-internet.fr>, jm
<jm@nospam.fr> wrote:

> I have written some perl client program and javascript server program.
> 
> Communication seams working in both direction, but the perl client
> cannot read final data.
> 
> Perl use socket in blocking mode (default).
> I open the connection with localhost, port number, and tcp.
> 
> 
> When I read packets with a size of 512 or 4096, everything works fine
> till the last packet. As the last packet is smaller than 4096, perl stay
> blocked waiting for a complete packet.
> 
> I just want it to be blocked when no byte is available.
> 
> When I do not use a size of 512 or 4096, but a size of 1, everything
> works fine, but I am wondering if it will not be too much slow.
> 
> my $buffer = '';
> while ( not $buffer =~ /\n\n/ )
> {
>   my $packet;
>   sysread $sock, $packet, 4096 ;
>   $buffer .= $packet ;
> }

How do you know the problem is not with your server? We can't tell,
since you have not shown us your code. You should 1) capture the return
value of sysread and check it for a) the number of bytes read, b) a 0
if the socket has been closed, or c) undef if an error has occurred,
and 2) print the return value and the bytes read, if any.

-- 
Jim Gibson

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


------------------------------

Date: Sat, 08 Mar 2008 00:05:56 +0100
From: jm <jm@nospam.fr>
Subject: Re: sample client server socket issue
Message-Id: <47d1ca54$0$21143$7a628cd7@news.club-internet.fr>

Jim Gibson a écrit :
> In article <47d071a9$0$21144$7a628cd7@news.club-internet.fr>, jm
> <jm@nospam.fr> wrote:
> 
>> I have written some perl client program and javascript server program.
>>
>> Communication seams working in both direction, but the perl client
>> cannot read final data.
>>
>> Perl use socket in blocking mode (default).
>> I open the connection with localhost, port number, and tcp.
>>
>>
>> When I read packets with a size of 512 or 4096, everything works fine
>> till the last packet. As the last packet is smaller than 4096, perl stay
>> blocked waiting for a complete packet.
>>
>> I just want it to be blocked when no byte is available.
>>
>> When I do not use a size of 512 or 4096, but a size of 1, everything
>> works fine, but I am wondering if it will not be too much slow.
>>
>> my $buffer = '';
>> while ( not $buffer =~ /\n\n/ )
>> {
>>   my $packet;
>>   sysread $sock, $packet, 4096 ;
>>   $buffer .= $packet ;
>> }
> 
> How do you know the problem is not with your server? We can't tell,
> since you have not shown us your code. You should 1) capture the return
> value of sysread and check it for a) the number of bytes read, b) a 0
> if the socket has been closed, or c) undef if an error has occurred,
> and 2) print the return value and the bytes read, if any.


When debugging the code, I had replaced sysread, by recv and read methods.

I moved back to the sysread, and it looks like working fine.

However, I am not sure documentation clearly explain why $sock->send for
sending, and why sysread for reading...

thanks.



------------------------------

Date: Fri, 07 Mar 2008 21:31:17 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Sending using Net::IRC
Message-Id: <9g73t3h8aleri78er25jntibv8133c7smf@4ax.com>

On Thu, 6 Mar 2008 21:58:25 -0800 (PST), deadpickle
<deadpickle@gmail.com> wrote:

>I am wondering is there a way to SEND PRIVMSG's to the channel
>(therefore making them public) using the module Net::IRC? This modeule
>does everything I need EXCEPT this, so if someone knows how to do this
>I would be forever greatful.

I don't know N::I, but I recently stumbled upon the following thread:

http://perlmonks.org/?node_id=671791

The discussion *seems* to boil down to: N::I is somewhat buggy.
Modules that one can use instead are POE::Component::IRC,
Bot::BasicBot or Parse::IRC (while manually handling the connection)
which is by appearent general consensus claimed to be the best IRC
parsing module.


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: Fri, 7 Mar 2008 11:41:06 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Using Perl to get data from website
Message-Id: <i7m7a5-h43.ln1@osiris.mauzo.dyndns.org>


Quoth fiazidris <fiazbfs@gmail.com>:
> Previously, I have written a perl script to access data from this URL:
> 
> http://www.bangkokflightservices.com/our_cargo_track.php
> 
> Some sample: MAWB - Master Airwaybill Number
> 
> 724-26332482
> 724-61480672
> 724-61441122
> 
> and this was the final URL:
> 
> http://203.151.118.123:8090/showc_track.php?m_prefix=724&m_sn=
> 26332482&h_prefix=HWB&h_sn=
> 
> But, now there is a change on the website and I couldn't extract
> through the same script. One change I noticed is the URL has changed
> to:
> 
[url trimmed]
> <iframe src="http://203.151.118.123:8090/showc_track.php?
> m_prefix=724&m_sn=26332482&h_prefix=HWB&h_sn=&ecy=e076438db64c61..."
> frameborder="0" scrolling="yes" height="700" width="100%"> </iframe>
> 
> How can I programmatically obtain data for a list of MAWBs.

Yuck, what a horrible page. <input> without <form>... I would use
something like

    #!/usr/bin/perl

    use WWW::Mechanize;

    my $baseurl =
        'http://www.bangkokflightservices.com/our_cargo_track&trace.php';
    my $hawb = 'h_prefix=HAWB&h_sn=';

    my $M = WWW::Mechanize->new(auto_check => 1);

    while (<>) {
        chomp;

        my ($mprefix, $msn) = /(...)(........)/ or do {
            warn "invalid MAWB: '$_'";
            next;
        };

        $M->get("$baseurl?m_prefix=$mprefix&m_sn=$msn&$hawb");
        $M->follow_link(url_regex => qr/showc_track/);
        my $content = $M->content;

        # process $content as before
    }

You may need to adjust the follow_link call if there are several links on
the same page that match that regex; see perldoc WWW::Mechanize for the
arguments. If the server checks the Referer, you may also need to ->get
/our_cargo_track.php first.

Ben



------------------------------

Date: Fri, 7 Mar 2008 06:46:52 -0800 (PST)
From: ifiaz <fiazidris@gmail.com>
Subject: Re: Using Perl to get data from website
Message-Id: <9ce33858-dcbe-401a-8e97-4369287153ea@n58g2000hsf.googlegroups.com>

You may need to adjust the follow_link call if there are several links
on
the same page that match that regex; see perldoc WWW::Mechanize for
the
arguments. If the server checks the Referer, you may also need to -
>get
/our_cargo_track.php first.

Ben
----

Thank you for your prompt response.

When I used the code with minor modifications, I still have the
problem that I can't access the data as the process throws me to
another page as below.

This is what the $content contains:

		<script> window.open ('http://www.bangkokflightservices.com/
our_cargo_track.php') ;
			setTimeout("window.close();", 10);
		</script>

How to get to the actual data page. Please guide me here as I am a
newbie.

I don't know how to implement Referer and all that.


### This is the complete code I used.
#!/usr/bin/perl

use WWW::Mechanize;

my $baseurl =
    'http://www.bangkokflightservices.com/our_cargo_track&trace.php';
my $hawb = 'h_prefix=HAWB&h_sn=';

my $M = WWW::Mechanize->new(auto_check => 1);

	## Added code for testing Only
	my $F = WWW::Mechanize->new(auto_check => 1);
	$F->get("http://www.bangkokflightservices.com/our_cargo_track.php");
	my $contentF = $F->content;
	#print "$contentF\n";
	#$M->add_header("Referer => 'http://www.bangkokflightservices.com/
our_cargo_track.php'" )

while (<>) {
    chomp;

    my ($mprefix, $msn) = /(...)-(........)/ or do {
        warn "invalid MAWB: '$_'";
        next;
    };

    print "$mprefix $msn\n";

    $M->get("$baseurl?m_prefix=$mprefix&m_sn=$msn&$hawb");
    $M->follow_link(url_regex => qr/showc_track/);
    my $content = $M->content;

    print "$content\n"; # for debugging

    # process $content as before
    #
      while ( $content =~ m#(.*)#g ) {
            $currline=$1;

            if ($currline =~ m#style12#i) {

                $currline =~ m#.*>(.*?)<.*#i;
                    $result = $result . " / " . $1;
            }
    }
    print "***$result\n";
    $result = '';
}


------------------------------

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 1341
***************************************


home help back first fref pref prev next nref lref last post