[21945] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4167 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 24 00:05:42 2002

Date: Sat, 23 Nov 2002 21:05:09 -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           Sat, 23 Nov 2002     Volume: 10 Number: 4167

Today's topics:
    Re: a CHAT room in CGI/Perl <goldbb2@earthlink.net>
    Re: a question on regular expression <usenet@dwall.fastmail.fm>
    Re: a question on regular expression <goldbb2@earthlink.net>
    Re: Binary vs ascii ??? <n_joeller@sharaziilyar.com>
    Re: Binary vs ascii ??? <bart.lateur@pandora.be>
    Re: Can pragma "use locale" affect sort function used i <goldbb2@earthlink.net>
    Re: comment on 2 or 4 spaces indentation <goldbb2@earthlink.net>
    Re: comment on 2 or 4 spaces indentation <jurgenex@hotmail.com>
    Re: complex foreach loop with deep hashes (sorted hash  (Jay Tilton)
    Re: complex foreach loop with deep hashes (sorted hash  <sheukels=cuthere=@yahoo.co.uk>
    Re: complex foreach loop with deep hashes (sorted hash  <goldbb2@earthlink.net>
    Re: complex foreach loop with deep hashes (sorted hash  <flavell@mail.cern.ch>
    Re: Cross-Platform method to get process information <mgjv@tradingpost.com.au>
    Re: disambiguating print (was Re: Basic syntax question <goldbb2@earthlink.net>
    Re: disambiguating print (was Re: Basic syntax question <bart.lateur@pandora.be>
    Re: disambiguating print (was Re: Basic syntax question <goldbb2@earthlink.net>
        Find Text in a variable <blnukem@hotmail.com>
    Re: Find Text in a variable <robertbu@hotmail.com>
    Re: Find Text in a variable <goldbb2@earthlink.net>
    Re: grep with multiple expressions <goldbb2@earthlink.net>
    Re: having problems parsing an error log. <goldbb2@earthlink.net>
    Re: NYC <dha@panix2.panix.com>
        OLE using ActiveState 5.8 <robertogallofilho@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 23 Nov 2002 21:38:47 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: a CHAT room in CGI/Perl
Message-Id: <3DE03BB7.456E9913@earthlink.net>

Walter Roberson wrote:
> 
> In article <armdv7$49j$1@news-reader12.wanadoo.fr>,
> Chocho  <el.chocho@laposte.net> wrote:
> :I want to write a CGI's script in Perl for a chat room.
> :This is the problem:
> :If user #1 post a message, it must be seen immediately by other users (like
> :in IRC's system)
> :But I don't know to do that...
> :An HTML refresh on the HTML's page generated by the script... it's not very
> :efficient ..
> 
> This isn't really a perl problem, this is an HTML problem.
> 
> The general approach in HTML would be (as I recall) to use a
> multipart/mixed MIME type, keep the connection open, and write each
> new update to the connection as multipart, not writing a plain
> singular part until the last one you want to send.

Not "multipart/mixed", but rather "multipart/mixed-replace".  These are
two different beasts.

> The only perl aspect here is to make sure you flush the buffer after
> writing each of the parts.

Not so.  The perl aspect is the use of already written modules for
performing this task -- CGI::Push, for example, or perhaps
multipart_{init,start,end,final} from CGI.pm.

Also... not only does the CGI script need to keep a connection open to
each web browser, but it also needs to communicate with the other
scripts who have connections open to other browsers.

That is not really a perl problem precisely, but there are perl
solutions -- IO::Socket if you want normal CGI scripts, which happen to
communicate with each other; or perhaps HTTP::Daemon, if you want to
have one web server handling *all* of the chat connections (obviously,
no inter-CGI communication would be needed).

Decide whether you want to use HTTP::Daemon, or ordinary CGI scripts
which communicate, and then we can help you more.

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Sat, 23 Nov 2002 23:08:43 GMT
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: a question on regular expression
Message-Id: <Xns92CFB8966A334dkwwashere@204.127.68.17>

"Kurt Gong" <gongwm@163.net> wrote:

> hello, i wanna find inverted repeats in dna sequence. for example:
> there are 4 different nucleotides in dna sequence: A, T, C ,G
> A pairs with T, and C pairs with G.
> the inverted repeats is something like :
> XXXXATCGXXXXCGATXXX, X represents one random nucleotide of A, T,
> C, G. this kind of pattern can form stem-loop structure which is
> very important for various molecular interaction.
> my question is how to construct a regular expression to find out
> such a pattern from a long dna sequence which may contains many of
> this inverted repeats.
> thanx in advance.

Maybe I misunderstood.  I thought you wanted to find ALL inverted 
sequences of a given length.  Anyway, here's a program that does 
that.  I don't guarantee it -- i just threw it together for fun.


-----------------
use strict;
use warnings;

my $min = 7;
my $max = 8;

my $dna;
{
    local $/ = undef;
    $dna = <>;
}
$dna =~ s/\s+//g;
$dna = lc $dna;

for my $repeat_length ($min .. $max) {
    for (
      my $offset=0; 
      $offset < length($dna) - $repeat_length; 
      $offset++
      ) {
        
        my $seq = substr $dna, $offset, $repeat_length;
        my $rev = reverse $seq;

        # runs of one base are boring
        next if
            $seq eq 'a' x $repeat_length or
            $seq eq 'g' x $repeat_length or
            $seq eq 't' x $repeat_length or
            $seq eq 'c' x $repeat_length;
        
        my @repeats = ();
        while ( $dna =~ /$rev/g ) {
            my $pos_found = pos($dna) - $repeat_length;
            next if
                    # palindrome
                ($offset == $pos_found)         
                    # overlap
                or ($offset + $repeat_length > $pos_found)  
                ;
            push @repeats, $pos_found;
        }
        # there may be duplicated sequences, of course
        # maybe 'repeats' should be a hash of ...
        print "$seq at $offset; $rev at at ", 
            join(', ', @repeats), "\n"
            if @repeats;

    }
}
-----------------


-- 
David Wall - usenet@dwall.fastmail.fm
"Oook."


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

Date: Sat, 23 Nov 2002 22:27:26 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: a question on regular expression
Message-Id: <3DE0471E.4560F1A7@earthlink.net>

Kurt Gong wrote:
> 
> hello, i wanna find inverted repeats in dna sequence. for example:
> there are 4 different nucleotides in dna sequence: A, T, C ,G
> A pairs with T, and C pairs with G. the inverted repeats is something
> like :
> XXXXATCGXXXXCGATXXX, X represents one random nucleotide of A, T, C, G.
> this kind of pattern can form stem-loop structure which is very
> important for various molecular interaction. my question is how to
> construct a regular expression to find out such a pattern from a long
> dna sequence which may contains many of this inverted repeats.

# assuming that the data *only* consists of A, T, C, G characters.

$data = ....;
while( $data =~ m[
   (  # match the forward part; it must have at least two
      # different characters to be of interest.
      (?> (.) \2* ) .+
   )
   (?= .* (
      (??{reverse $1})
   ) )
]xig ) {
   print "From $-[1] to $+[1] is '$1'\n";
   print "From $-[3] to $+[3] is '$3' (it's mirror)\n";
}

[untested]

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Sun, 24 Nov 2002 00:14:21 GMT
From: Noerd <n_joeller@sharaziilyar.com>
Subject: Re: Binary vs ascii ???
Message-Id: <3DE019BD.D2F3A9F@sharaziilyar.com>



Tad McClellan wrote:

> Noerd <n_joeller@sharaziilyar.com> wrote:
>
> > My home computer's FTP client gives me the choice of uploading files in
> > binary, ascii, etc. My webserver uses Linux w/ Apache.
>
> We have half of the info needed.
>
> What OS is at the other end of the FTP (ie. on your home computer).
>
> If you are transferring unix-to-unix, ASCII and binary FTP mode
> will behave identically, so it makes no difference.
>
> If you are transferring windows-to-unix then...
>
> > I've chosen to do ALL uploads and downloads in binary only. This
> > includes both Perl scripts, and textfiles.
>
> ... you have made an extremely poor choice.  :-)
>
> > In recently reviewing many Perl manuals, the recommendation is NOT to
> > upload in binary, but to use ascii.
>
> Right, if transferring between dissimilar systems.
>
> > My question is as follows: could there be a possible performance hit by
> > uploading my Perl scripts, textfiles etc., in binary? Or is it simply a
> > situation of either it WILL work, or it WON'T work.
>
> If windows-to-unix, then binary mode probably WON'T work.
>
> > What potential problems are there in uploading in binary?
>
> The line-ending sequence will not be properly translated,
> and the shebang line method of running programs won't work.
>
> > I'm not trying
> > to be a contrarian; I just remember hearing a long time ago from a
> > genius programmer that with Unix/Linux binary is always better.
>
> You cannot determine which is "better" unless you know what
> OS is at _each_ end of the transfer.
>
> --
>     Tad McClellan                          SGML consulting
>     tadmc@augustmail.com                   Perl programming
>     Fort Worth, Texas

I'm using Macintosh OS9 for my home computer.

But, another part of my question (i didn't mention this) is this:

Lets say I upload a Perl script using EITHER binary, or ascii. When I SSH
into my webserver, the script looks identical. But, if I were to guess, I
would think that all the "invisible" characters are filtered out. What do
you think???

thanks




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

Date: Sun, 24 Nov 2002 01:00:11 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Binary vs ascii ???
Message-Id: <bu80uu08q8jo3cuh5athsv5p8gktcj6d43@4ax.com>

Noerd wrote:

>I'm using Macintosh OS9 for my home computer.

Oops. Not compatible. Unix uses *only* a chr(10) as a line end marker,
MacOS uses *only* a chr(13). Not compatible.

>But, another part of my question (i didn't mention this) is this:
>
>Lets say I upload a Perl script using EITHER binary, or ascii. When I SSH
>into my webserver, the script looks identical. But, if I were to guess, I
>would think that all the "invisible" characters are filtered out. What do
>you think???

I think the invisible characters, in particular the chr(13) and chr(10)
I mentioned earlier, maybe got substituted. 

-- 
	Bart.


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

Date: Sat, 23 Nov 2002 21:23:21 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Can pragma "use locale" affect sort function used in module method?
Message-Id: <3DE03819.A88C0F6@earthlink.net>

Darek Adamkiewicz wrote:
> 
> Hello folks,
> I can't figure out how this could be done - if this could be done
> - perhaps anybody enlighten me?

sub themethod {
   my $caller_hints = (caller(1))[8];
   if( $caller_hints & $locale::hint_bits ) {
      use locale;
      @sorted = sort @unsorted;
   } else {
      no locale;
      @sorted = sort @unsorted;
   }
}

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Sat, 23 Nov 2002 21:48:35 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: comment on 2 or 4 spaces indentation
Message-Id: <3DE03E03.14FA8C3E@earthlink.net>

Gary Fu wrote:
> 
> Hi,
> 
> My colleague uses emacs and had hard time to modify Perl program with
> 2 spaces indentation.  He told me that 4 spaces indentation is
> standard for Perl and the tab in emacs will do that automatically. 
> However, I'm a vi user, don't use tab (may be expanded to different
> number of spaces on different editors), prefer with 2 spaces
> indentation (to save stroke and line spaces).
> Any comment why 4 spaces indentation is standard or better than 2
> spaces for Perl ?

As others have said, there is no standard indentation.

The advantage of 4 spaces is readability.
The advantage of 2 spaces is less typing.

Personally, I prefer 3 spaces ... I used to use 2 spaces, but on
occasion, I would look at a piece of code where I'd typoed on the number
of spaces, and couldn't tell if I'd put in one too few, or one too many.

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Sun, 24 Nov 2002 02:45:24 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: comment on 2 or 4 spaces indentation
Message-Id: <83XD9.11938$mL2.10854@nwrddc01.gnilink.net>

Benjamin Goldberg wrote:
> As others have said, there is no standard indentation.
>
> The advantage of 4 spaces is readability.
> The advantage of 2 spaces is less typing.

Well, no. Or only with not-so-smart editors.
A decent editor will automatically indent as many spaces as you want as soon
as you hit the enter key. I mean, who would want to count the spaces for the
indentation manually?

jue




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

Date: Sat, 23 Nov 2002 23:06:29 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: complex foreach loop with deep hashes (sorted hash slices (using an array for keys))
Message-Id: <3ddff719.204116254@news.erols.com>

[ As a courtesy to readers interested in assisting you, please read the
posting guidelines at http://mail.augustmail.com/~tadmc/clpmisc.shtml .

The follow-up article had no information from the original to provide
context, so readers have to do extra work to get an overview of the
original problem. ]

On Sat, 23 Nov 2002 22:07:14 +0100, "Seansan"
<sheukels=cuthere=@yahoo.co.uk> wrote:

: I use the following loop code to loop through a list contained in %LIST. The
: list keys are IDs, the value is an array containing about 5 values.

Also called a "hash-of-arrays."

: This
: loop sorts list items based on $x (0-4), based on what I want to sort on
: within the array within the hash. Still with me?

: foreach $no (sort {uc @{$LIST{$a}}[$x] cmp uc @{$LIST{$b}}[$x]} %LIST)
                                                                  ^^^^^
You most probably mean "keys %LIST" there.                        ^^^^^
 
: How do I make the code functional exactly as it does, but also include the
: possibility to not iterate over the whole %LIST, but only the Hash IDs that
: are contained in another array @G_ITEMS ?

At 22:18:03 +0100, "Seansan" added:

: After some usenet browsing I figured the following would solve the problem :
: 
: foreach (keys %{@LIST{@G_ITEMS}}) {print "<LI> $_\n";}
: 
: But this returns the error :
: Can't use an undefined value as a HASH reference at

Since the values in @G_ITEMS are keys to the %LIST hash, drop it in
right where "keys %LIST" appeared before.  While we're here, let's clean
up some of that dereferencing punctuation.

    foreach $no (sort {uc $LIST{$a}[$x] cmp uc $LIST{$b}[$x]} @G_ITEMS)
    {
        # do stuff
    }

: (also posted in comp.lang.perl)

comp.lang.perl does not exist except as a phantom group that your news
server admin has neglected to remove.

But if it was a legitimate group, cross-posting your article would have
been more appropriate than multi-posting.  
See http://www.dickalba.demon.co.uk/usenet/guide/faq_cros.html .



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

Date: Sun, 24 Nov 2002 00:43:58 +0100
From: "Seansan" <sheukels=cuthere=@yahoo.co.uk>
Subject: Re: complex foreach loop with deep hashes (sorted hash slices (using an array for keys))
Message-Id: <3de012b4$0$2246$e4fe514c@dreader6.news.xs4all.nl>

Right. Thx Jay Tilton for nothing.

> > foreach $no (sort {uc @{$LIST{$a}}[$x] cmp uc @{$LIST{$b}}[$x]} keys
%LIST)
>                                                                 ^^^
> where is the call to the "keys" function ?
sry. forgot to add the keys. (I was playing with the code), but already
tried that :: returns an error still
and $x is the array element I sort on, in this example it might as well be 1
or 2
New: foreach $no (sort {uc @{$LIST{$a}}[1] cmp uc @{$LIST{$b}}[1]} keys
%LIST)

> If you had "keys %LIST" there as you should, then you could
> just replace it with @G_ITEMS.
Then the sort doesnt work

> Is that truly the code you have?
Yes.
Any improvements I can make with the same effect?

> What's with the one-element slices?
That how sort works, if I understand correctly that you are refering to  at
the $a and $b.
> Do you have warnings enabled?
Nope. Could do, but its just a code tidbit I use.

I'm just interested in the use of hash slices with this particuliar problem

> You should not post to comp.lang.perl, it was removed about 7 *years*
ago...
Works fine.

Thx in advance, Sean

"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnau01ch.3pa.tadmc@magna.augustmail.com...
> Seansan <sheukels=cuthere=@yahoo.co.uk> wrote:
>

>
>
> > How do I make the code functional exactly as it does,
>
>
> I doubt that you want it to do exactly what it does.
>
> It uses array refs as hash keys.
>
>
> > but also include the
> > possibility to not iterate over the whole %LIST, but only the Hash IDs
that
> > are contained in another array @G_ITEMS ?
>
>
> If you had "keys %LIST" there as you should, then you could
> just replace it with @G_ITEMS.
>
>
> > doing somethin to the original code :
> >
> > foreach $no (sort {uc @{$LIST{$a}}[$x] cmp uc @{$LIST{$b}}[$x]} %LIST)
>                         ^                       ^
>
> Is that truly the code you have?
>
> What's with the one-element slices?
>
> Do you have warnings enabled?
>
>
> > (also posted in comp.lang.perl)
>
>
> That was a double mistake.
>
> You should not post individually to multiple newsgroups, you
> should instead make a single article and crosspost it to
> both groups.
>
> You should not post to comp.lang.perl, it was removed
> about 7 *years* ago...
>
>
> --
>     Tad McClellan                          SGML consulting
>     tadmc@augustmail.com                   Perl programming
>     Fort Worth, Texas




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

Date: Sat, 23 Nov 2002 21:57:33 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: complex foreach loop with deep hashes (sorted hash slices (using an array for keys))
Message-Id: <3DE0401D.97DF80B2@earthlink.net>

Seansan wrote:
[snip]
> foreach $no (sort {uc @{$LIST{$a}}[$x] cmp uc @{$LIST{$b}}[$x]} %LIST)

This code is quite wrong -- I can't imagine how it could have worked at
all.  What do you think that uc @{$LIST{$a}}[$x] does?  And of course,
you're iterating over both the keys and the values of %LIST, since you
ommited the keys operator.

> How do I make the code functional exactly as it does, but also include
> the possibility to not iterate over the whole %LIST, but only the Hash
> IDs that are contained in another array @G_ITEMS ?

foreach my $number (
   sort {
      uc( $LIST{$a}[$x] ) cmp uc( $LIST{$b}[$x] ) 
   } grep $LIST{$_}, @G_ITEMS
) {
   ...
}

This assumes that no item is in @G_ITEMS more than once... or, if it is
in there more than once, you don't mind iterating over that item more
than once.

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Sun, 24 Nov 2002 00:50:21 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: complex foreach loop with deep hashes (sorted hash slices (using an array for keys))
Message-Id: <Pine.LNX.4.40.0211240047540.19629-100000@lxplus073.cern.ch>

On Nov 24, Seansan inscribed on the eternal scroll:

> Right. Thx Jay Tilton for nothing.

I was mistaken - it wasn't happy plonk Friday, it was happy plonk
week.  How sad, when there are still a few folks around who are trying
to help.

[TOFU environmentally recycled]



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

Date: Sun, 24 Nov 2002 14:05:42 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Cross-Platform method to get process information
Message-Id: <slrnau0gg6.1rk.mgjv@martien.heliotrope.home>

On 23 Nov 2002 20:45:13 GMT,
	Rafael Garcia-Suarez <rgarciasuarez@free.fr> wrote:
> Jeff Walter wrote in comp.lang.perl.misc :
>>     I have a script that needs to check the status and PID of processes by
>> command name.  Right now I have it running as just substr'ing the results of
>> "ps axu | grep cmd".  Problem is, the results are formatted differently on
>> BSD from RedHat.  So is there a module to do this sort of thing?
> 
> There are some Proc::* modules on CPAN. Proc::ProcessTable may be the
> one you're looking for.
> 
> Note also that the ps that comes with most Linux distributions is quite
> flexible. Check its manpage for the -e option.

But, since the OP was asking for a cross-platform way, it is better not
to use ps. There are many different ps versions out there, and they all
format differently, and take different arguments. The BSD ps variants
will do that "ax" thing, but SYSV variants won't; these two variants
have totally different command line interfaces. The GNU ps seems to be
the only one that takes both sets of arguments.

Using the Proc:: modules is likely to be much more successful, and more
cross-platform. Of course, it'll still be limited to systems where
process info is available like that.

Martien
-- 
                        | 
Martien Verbruggen      | If it isn't broken, it doesn't have enough
                        | features yet.
                        | 


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

Date: Sat, 23 Nov 2002 18:31:10 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: disambiguating print (was Re: Basic syntax question on using arrays returned from function)
Message-Id: <3DE00FBE.2806DEC5@earthlink.net>

Tad McClellan wrote:
[snip]
> We've been talking about the unary + in this thread.
> 
> The ambiguity problem we've been discussing is a consequence
> of Larry's decision to make parenthesis around function
> arguments optional rather than required.
> 
> If we happen to choose to use parens, then perl's job (finding
> the end of the arg list) is easy, it just finds the matching
> (perhaps nested) closing parenthesis.
> 
> It must use some other means of detecting the end of the arg
> list for folks who choose to leave the parenthesis off.

If there's no parens, the arg list goes to the end of the statement
(marked by either ";" or "}" or EOF), or until it finds an operator
whose precedence is lower than a list operator (one of "not", "and",
"or", "xor").

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Sun, 24 Nov 2002 00:56:09 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: disambiguating print (was Re: Basic syntax question on using arrays returned from function)
Message-Id: <4s80uuc70lgaehlcj080pc50u8v156t280@4ax.com>

Benjamin Goldberg wrote:

>> It must use some other means of detecting the end of the arg
>> list for folks who choose to leave the parenthesis off.
>
>If there's no parens, the arg list goes to the end of the statement
>(marked by either ";" or "}" or EOF), or until it finds an operator
>whose precedence is lower than a list operator (one of "not", "and",
>"or", "xor").

For print()? Yes. But not in the general case, not in regards to
function prototypes.

-- 
	Bart.


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

Date: Sat, 23 Nov 2002 20:36:16 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: disambiguating print (was Re: Basic syntax question on using arrays returned from function)
Message-Id: <3DE02D10.C118F4A3@earthlink.net>

Bart Lateur wrote:
> 
> Benjamin Goldberg wrote:
> 
> >> It must use some other means of detecting the end of the arg
> >> list for folks who choose to leave the parenthesis off.
> >
> >If there's no parens, the arg list goes to the end of the statement
> >(marked by either ";" or "}" or EOF), or until it finds an operator
> >whose precedence is lower than a list operator (one of "not", "and",
> >"or", "xor").
> 
> For print()? Yes. But not in the general case, not in regards to
> function prototypes.

For print or any other list operator it is.

Also, for any function whose prototype ends in '@' or '%' and whose
requirements for the earlier arguments have already been met.

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Sun, 24 Nov 2002 00:01:49 GMT
From: "Blnukem" <blnukem@hotmail.com>
Subject: Find Text in a variable
Message-Id: <NFUD9.34009$op6.28777@news4.srv.hcvlny.cv.net>

Hi All

I have a variable that contains the following:

$content = "(mac address: 00-20-52-d7-76-d6) ip address:192.168.1.1dhcp
server:disabled wan:(mac address: 00-24-65-d1-78-b7) ip
address:254.52.585.547 subnet mask:255.255.252.0 '";

What is the best way to retrieve the "254.52.585.547" number out of this
string and put that number it into a new variable. This number may be
deferent at times so I can't match the exact number.

Thanx in advance
Blnukem




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

Date: Sun, 24 Nov 2002 01:19:38 GMT
From: "robertbu" <robertbu@hotmail.com>
Subject: Re: Find Text in a variable
Message-Id: <KOVD9.3107$D73.499@nwrddc03.gnilink.net>


"Blnukem" <blnukem@hotmail.com> wrote:
>
> I have a variable that contains the following:
>
> $content = "(mac address: 00-20-52-d7-76-d6) ip address:192.168.1.1dhcp
> server:disabled wan:(mac address: 00-24-65-d1-78-b7) ip
> address:254.52.585.547 subnet mask:255.255.252.0 '";
>
> What is the best way to retrieve the "254.52.585.547" number out of this
> string and put that number it into a new variable. This number may be
> deferent at times so I can't match the exact number.

$content =~  /ip address:([0-9.]+)/;
print "$1\n";

== Rob ==




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

Date: Sat, 23 Nov 2002 22:02:52 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Find Text in a variable
Message-Id: <3DE0415C.2A64C53F@earthlink.net>

robertbu wrote:
[snip]
> $content =~  /ip address:([0-9.]+)/;
> print "$1\n";

And what happens if the string happens not to contain that pattern?

This will end up printing whatever was in $1 before you did the match.

Oops.

Conclusion: Never use dollar-digit variables unless you're *sure* that
the pattern matched.

my ($ip) = $content =~  /ip address:([0-9.]+)/;
print( defined($ip) ? ($ip, "\n") : "No match\n" );


-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Sat, 23 Nov 2002 21:19:19 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: grep with multiple expressions
Message-Id: <3DE03727.54981E20@earthlink.net>

Jay Tilton wrote:
> 
> n9pgm@xnet.com wrote:
> 
> : I don't know if grep is the right function for what I need to do.
> 
> Filtering elements from one list into another?
> grep() is exactly the right tool.
> 
> : I'm trying to use grep where there are multiple search arguments,
> : and I want to find the records in a flat file that contain any of
> : the arguments.
> :
> : If there are a fixed number of arguments, and only a few of them,
> : then I can do:
> :
> : @hits = grep (/$arg1/ || /$arg2/ || /$arg3/, <DAT>);
> :
> : But the number of arguments is different from one execution of the
> : script to the next, and there may be several arguments. So I'm
> : looking for something like:
> :
> : @hits = grep (@args, <DAT>);
> :
> : Is there some way to do this?
> 
>     my @hits = grep
>         &{sub{
>             for my $arg (@args) {
>                 return 1 if /$arg/;
>             }
>             return 0;
>         }},
>         <DAT>;

Bleh -- that's icky.  Try this instead:

   grep {
      my $any;
      for my $regex (@args) {
         last if $any = /$regex/;
      }
      $any;
   } <DAT>;


-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Sat, 23 Nov 2002 21:14:25 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: having problems parsing an error log.
Message-Id: <3DE03601.DC4F8F61@earthlink.net>

JimL. wrote:
> 
> I am trying to write a script to capture some specifics of an error
> log.
> the log sample is as follows:
[snip]
> Now I'm STUCK!! Can anyone help get me kickstarted again?

I would suggest that instead of parsing it as you have been, try and
seperate the log file into records, then deal with the records.

my @record;
while( <> ) {
   # remove $/ from the end of $_.
   chomp;

   # If necessary, alter $/ to include ^M, so chomp removes it.
   if( m?(\CM?)\z? ) {
      chop($_) if $1;
      $/ = "$1\n";
   }

   push @record, $_;

   # if we don't have a complete record, continue
   # looping, so as to add more lines.
   next if !eof() and (@record < 3 or /\*\CM?\z/);

   # deal with this [now complete] record.

   my ($date, $error, $info, @offsets) =
      eof() ? @record : splice(@record, 0, -1);

   # If this isn't one we're interested in, continue.
   next unless $error =~ /\bBad Password\b/;

   # Do the real processing here:
   print "On date $date, the offsets were:\n";
   print $_, "\n" for @offsets;

} continue {
   ($/ = "\n"), reset if eof;
}


-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Sun, 24 Nov 2002 01:53:37 +0000 (UTC)
From: "David H. Adler" <dha@panix2.panix.com>
Subject: Re: NYC
Message-Id: <slrnau0c91.mlg.dha@panix2.panix.com>

In article <OQeD9.2848$EY.175@fe01>, Ta Nea wrote:
> If there is a Perl developer in the NYC area I need to speak with you for a
> small project.

You have posted a job posting or a resume in a technical group.

Longstanding Usenet tradition dictates that such postings go into
groups with names that contain "jobs", like "misc.jobs.offered", not
technical discussion groups like the ones to which you posted.

Had you read and understood the Usenet user manual posted frequently to
"news.announce.newusers", you might have already known this. :)  (If
n.a.n is quieter than it should be, the relevent FAQs are available at
http://www.faqs.org/faqs/by-newsgroup/news/news.announce.newusers.html)
Another good source of information on how Usenet functions is
news.newusers.questions (information from which is also available at
http://www.geocities.com/nnqweb/).

Please do not explain your posting by saying "but I saw other job
postings here".  Just because one person jumps off a bridge, doesn't
mean everyone does.  Those postings are also in error, and I've
probably already notified them as well.

If you have questions about this policy, take it up with the news
administrators in the newsgroup news.admin.misc.

http://jobs.perl.org may be of more use to you

Yours for a better usenet,

dha

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
Honk if you love Perl! (or strawberries!) - Larry Wall


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

Date: Sat, 23 Nov 2002 22:07:18 -0200
From: "Roberto Gallo" <robertogallofilho@hotmail.com>
Subject: OLE using ActiveState 5.8
Message-Id: <arp56s$fen$1@aracaju.ic.unicamp.br>



    Hi,

    I would like to know how to use OLE Automaion with MS-Word on Win32
ActiveState  Distribution to:
    * open an MS-Word document and;
     * read/write some words from/to it.

    Thank you.




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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 4167
***************************************


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