[17774] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5194 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Dec 25 00:05:34 2000

Date: Sun, 24 Dec 2000 21:05:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <977720710-v9-i5194@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 24 Dec 2000     Volume: 9 Number: 5194

Today's topics:
        A question on pattern matching. koppum@my-deja.com
    Re: A question on pattern matching. <revjack@revjack.net>
    Re: A question on pattern matching. <uri@sysarch.com>
    Re: A question on pattern matching. (Brian Pontz)
    Re: A question on pattern matching. (Tad McClellan)
    Re: A question on pattern matching. <johnm@acadiacom.net>
    Re: A question on pattern matching. <uri@sysarch.com>
    Re: Argument isn't numeric and Win32::API <bjoern@hoehrmann.de>
    Re: Cloning an Object. (Tad McClellan)
    Re: cookie accepted or not ? <Juha.Laiho@iki.fi>
        Copy data from outside page <a@a>
    Re: Copy data from outside page <uri@sysarch.com>
    Re: DBD:mysql <bowman@montana.com>
        Does anyone know hoe to get sendmail to work on webprov <isithotinhere@orisitjustme.com>
    Re: Does anyone know hoe to get sendmail to work on web <you.will.always.find.him.in.the.kitchen@parties>
    Re: Does anyone know hoe to get sendmail to work on web <fire@bahl.hot>
    Re: Does anyone know hoe to get sendmail to work on web (David Efflandt)
    Re: FAQ 5.3:   How do I count the number of lines in a  (Chris Fedde)
    Re: Help Bidirectional IPC with IPC::Open2 <usenet@hank.org>
    Re: Help Bidirectional IPC with IPC::Open2 (David Efflandt)
    Re: infinite loop <wescott@conterra.com>
        making unique list of words matching a pattern (Vivekvr)
    Re: making unique list of words matching a pattern <bwalton@rochester.rr.com>
        Merry Christmas Pearl <godzilla@stomp.stomp.tokyo>
    Re: Need help finding a space in a string with "index" <waltman@netaxs.com>
    Re: Perl guru's comments on creating nasted hashes! (Randal L. Schwartz)
    Re: perl.com web site vs. browsers (Joe Smith)
    Re: testing if $_ is equal to some string? <virtualvat@yahoo.com>
    Re: what's the 1st line os perl script ? <waltman@netaxs.com>
    Re: Where can I get CRYPT for DOS/WIN? <virtualvat@yahoo.com>
    Re: Where can I get CRYPT for DOS/WIN? (Tad McClellan)
    Re: Where can I get CRYPT for DOS/WIN? fallenang3l@my-deja.com
    Re: Where to obtain the perlrtfm podpage? <bbollenbach@homenospam.com>
    Re: Yesterdays Date <waltman@netaxs.com>
    Re: Yesterdays Date <anmcguire@my-deja.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Sun, 24 Dec 2000 15:55:48 GMT
From: koppum@my-deja.com
Subject: A question on pattern matching.
Message-Id: <9256a3$29r$1@nnrp1.deja.com>

Hi,

I have the following problem when I try to match a string.

example:

$str1 = 'ABC$XYZ';
$str2 = 'C$X'

Now I like to detect (and may be make a substitution) the above
condition that $str1 contains $str2, like say:

if ($str1 =~ /$str2/) {....

The problem is that whenever there are characters like '$' perl treats
it as a character with special meaning (end of line).

Now, is there a modifier or something that I can do to let perl know
that I want to turn-off that special meaning for those characters like
$. I consulted several books (programming perl, cookbook etc.) but
without any success.

Any help is highly appreciated.
Thanks in advance.
Murali


Sent via Deja.com
http://www.deja.com/


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

Date: 24 Dec 2000 16:31:10 GMT
From: revjack <revjack@revjack.net>
Subject: Re: A question on pattern matching.
Message-Id: <9258ce$8e$1@news1.Radix.Net>
Keywords: Hexapodia as the key insight

Brian Pontz <pontz@NO_SPAM.channel1.com> wrote:
:>Now, is there a modifier or something that I can do to let perl know
:>that I want to turn-off that special meaning for those characters like
:>$. I consulted several books (programming perl, cookbook etc.) but
:>without any success.

: The backslash ( \ ) operator will "escape" any special meaning.

Yes...

: if ($str1 =~ /\$str2/) {....

er, I don't think that will solve his problem...

The OP should check out perldoc -f quotemeta

  $str2 = quotemeta 'C$X';

This works for the example given.

-- 
___________________
revjack@revjack.net



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

Date: Sun, 24 Dec 2000 16:38:25 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: A question on pattern matching.
Message-Id: <x766k9dbb3.fsf@home.sysarch.com>

>>>>> "BP" == Brian Pontz <pontz@NO_SPAM.channel1.com> writes:

  >> Now, is there a modifier or something that I can do to let perl know
  >> that I want to turn-off that special meaning for those characters like
  >> $. I consulted several books (programming perl, cookbook etc.) but
  >> without any success.

  BP> The backslash ( \ ) operator will "escape" any special meaning.

  BP> if ($str1 =~ /\$str2/) {....

that doesn't do anything useful for the OP. he wants to escape the $
INSIDE $str2. you just checked to see if the literal '$str2' is found in
$str1

the proper answer is quotemeta() or its interpolated version \Q.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Sun, 24 Dec 2000 17:15:25 GMT
From: pontz@NO_SPAM.channel1.com (Brian Pontz)
Subject: Re: A question on pattern matching.
Message-Id: <3a462ef7.227671724@news.ne.mediaone.net>

>The OP should check out perldoc -f quotemeta
>
>  $str2 = quotemeta 'C$X';

True. I must have misunderstood what he was asking for.

Brian Pontz


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

Date: Sun, 24 Dec 2000 11:12:02 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: A question on pattern matching.
Message-Id: <slrn94c82i.6sl.tadmc@magna.metronet.com>

Brian Pontz <pontz@NO_SPAM.channel1.com> wrote:
>>The OP should check out perldoc -f quotemeta
>>
>>  $str2 = quotemeta 'C$X';
>
>True. I must have misunderstood what he was asking for.


*All three* of the followups I have seen have misunderstood
what he was asking for.

He wants to find a substring in a longer string, no need
for "patterns" to get that done.

What's with the regexen? (rhetorical, the Subject drew you into
giving the wrong answer).


[ It is because the OP's post was a case of the X-Y problem.
  Rather than say what he wanted to accomplish, he asked about
  one of the ways of getting there. You shouldn't do that,
  because there may be a *better* way of getting there that
  hasn't occured to you.
]


   if ( index($str1, $str2) != -1 )
      { print "matched\n" }
   else
      { print "No match\n" }



-- 
    Tad McClellan                          SGML consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Sun, 24 Dec 2000 19:56:12 -0600
From: "John Michael" <johnm@acadiacom.net>
Subject: Re: A question on pattern matching.
Message-Id: <3a46ab6c$1@news.acadiacom.net>

I may be wrong, but you need to do a print to evaluate:
$str1 and $str2 and see what is really going on.
I think you will find that the $ sign is not present.
Perl treats that $ dollar sign in the assignment as a scalar variable and
replaces it, whether it exist or not.
To use the $ sign in the string, you need to preceed it with a  \
This keeps perl from evaluating $XYZ as a scalar variable.
try
$str1 = 'ABC\$XYZ';
and see what you get.

Hope this helps.


<koppum@my-deja.com> wrote in message news:92562b$27d$1@nnrp1.deja.com...
> Hi,
>
> I have the following problem when I try to match a string.
>
> example:
>
> $str1 = 'ABC$XYZ';
> $str2 = 'C$X'
>
> Now I like to detect (and may be make a substitution) the above
> condition that $str1 contains $str2, like say:
>
> if ($str1 =~ /$str2/) {....
>
> The problem is that whenever there are characters like '$' perl treats
> it as a character with special meaning (end of line).
>
> Now, is there a modifier or something that I can do to let perl know
> that I want to turn-off that special meaning for those characters like
> $. I consulted several books (programming perl, cookbook etc.) but
> without any success.
>
> Any help is highly appreciated.
> Thanks in advance.
> Murali
>
>
> Sent via Deja.com
> http://www.deja.com/




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

Date: Mon, 25 Dec 2000 04:05:42 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: A question on pattern matching.
Message-Id: <x71yuxcfhl.fsf@home.sysarch.com>

>>>>> "JM" == John Michael <johnm@acadiacom.net> writes:

  JM> I may be wrong, but you need to do a print to evaluate:

sorry to say, but you are.

  JM> I think you will find that the $ sign is not present.  Perl treats
  JM> that $ dollar sign in the assignment as a scalar variable and
  JM> replaces it, whether it exist or not.

  JM> $str1 = 'ABC\$XYZ';
              ^        ^

  >> $str1 = 'ABC$XYZ';
             ^       ^ 

  >> $str2 = 'C$X'
             ^   ^

hmm, what is the same about all the marked characters? could it be that
they are single quotes and as such they do not interpolate.

and don't compound your mistake by jeopardy posting. find the recently
posted rules posting here to learn more about that. and read perldata
and perlop for more on quotes.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Mon, 25 Dec 2000 04:22:42 +0100
From: Bjoern Hoehrmann <bjoern@hoehrmann.de>
Subject: Re: Argument isn't numeric and Win32::API
Message-Id: <3a47ade7.10421194@news.bjoern.hoehrmann.de>

* Rick Delaney wrote in comp.lang.perl.misc:
>> my $path = 'e:\temp\agt\data\\';
>> my $HGrp = "";
>> 
>> $AgtGrpOpen->Call($path, $HGrp);
>> print $AgtGrpCount->Call($HGrp);
>> $AgtGrpClose->Call($HGrp);
>> 
>> Perl complains 'Argument "" isn't numeric in subroutine entry'. I don't
>> know, how I can change this, the value of $HGrp is under control of the
>> DLL function, I can only set the initial value to something numeric, but
>> if I do so, the script stops working, i.e. $count is -1 instead of the
>> correct value 18373.
>
>I know nothing about Win32::API, but what number are you passing?

I don't know what the DLL function writes to $HGrp, if Perl says it's ""
i can believe that. Actually it should be a pointer.

>If it
>works with "" but gives you that warning, then I'd expect it would work
>without the warning if you passed 0.

If I use 'my $HGrp = 0' Perl crashes (access violation).

>Then again, you have 3 different
>calls so I don't know if the warning is only coming from one of them.

It comes twice, for count() and close(). I defined the first argument to
be numeric in the constructor.

>You can always turn off warnings.

Yes, but I'm searching for "the right thing to do" [tm] :-)

Btw, `perldoc Win32::API` says:

| [...] Also note that memory
| must be allocated before calling the function. For example, if I want to
| pass a buffer of 80 characters to GetTempPath(), I have to initialize it
| before with:
| 
|     $lpBuffer = " " x 80;
| 
| This allocates a string of 80 characters. If you don't do so, you'll
| probably get '`Runtime exception'' errors, and generally nothing will
| work. My call should therefore include:
| 
|     $lpBuffer = " " x 80;
|     $GetTempPath->Call(80, $lpBuffer);

I actually can't do that, as written before.
-- 
Björn Höhrmann ^ mailto:bjoern@hoehrmann.de ^ http://www.bjoernsworld.de
am Badedeich 7 ° Telefon: +49(0)4667/981ASK ° http://bjoern.hoehrmann.de
25899 Dagebüll # PGP Pub. KeyID: 0xA4357E78 # http://learn.to/quote [!]e
      "XSL requires thinking -- not chatting" -- Dimitre Novatchev      


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

Date: Sun, 24 Dec 2000 11:20:18 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Cloning an Object.
Message-Id: <slrn94c8i2.6sl.tadmc@magna.metronet.com>

koppum@my-deja.com <koppum@my-deja.com> wrote:
>
>I am trying to clone an object. Can someone tell if there is a
>Class available in perl that let me do that (like Clonable in Java)?
>Or anywhere on the net that I could get some info about it? I tried to
>look at some places like perlpod etc.


You missed one then. Perl FAQ, part 4:

   "How do I print out or copy a recursive data structure?"

makes some mention of a 'dclone' function in Storable that
makes deep copies of data structures.


-- 
    Tad McClellan                          SGML consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 24 Dec 2000 11:13:33 +0200
From: Juha Laiho <Juha.Laiho@iki.fi>
Subject: Re: cookie accepted or not ?
Message-Id: <924ent$ohk$1@ichaos.ichaos-int>

vthnts@hotmail.com said:
>I use print "Set-cookie ..." to install a cookie.
>It works fine.

Meaning the cookie will be sent to the client, apparently.

>But I wonder how to know, before moving forward into my script, if the
>cookie has REALLY been installed.

You will only know that when new requests start coming in with your
cookie set in the request.
-- 
Wolf  a.k.a.  Juha Laiho     Espoo, Finland
(GC 3.0) GIT d- s+: a- C++ UH++++$ UL++++ P+@ L+++ E(-) W+$@ N++ !K w !O
         !M V PS(+) PE Y+ PGP(+) t- 5? !X R tv--- b+ DI? D G e+ h--- r+++ y+
"...cancel my subscription to the resurrection!" (Jim Morrison)


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

Date: Mon, 25 Dec 2000 12:11:43 +0800
From: "Victor" <a@a>
Subject: Copy data from outside page
Message-Id: <926h3d$883@news.cityu.edu.hk>

Hello,

I would like to provide weather information in my web page.

Could anyone teach me how to use cgi to copy information/data from an
outside html page.

Thanks!





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

Date: Mon, 25 Dec 2000 04:45:18 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Copy data from outside page
Message-Id: <x7y9x5az35.fsf@home.sysarch.com>

>>>>> "V" == Victor  <a@a> writes:

  V> I would like to provide weather information in my web page.

  V> Could anyone teach me how to use cgi to copy information/data from an
  V> outside html page.

use LWP ;

or 

use LWP::Simple

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Sun, 24 Dec 2000 09:40:11 -0700
From: "bowman" <bowman@montana.com>
Subject: Re: DBD:mysql
Message-Id: <IKp16.8079$wE3.7923@newsfeed.slurp.net>


hotschi <jenshoja@t-online.de> wrote in message
news:91nmbi$oj2$04$1@news.t-online.com...
>
> can anyone tell me where I can download the DBD driver for mysql.

CPAN or possibly ActiveState.




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

Date: Sun, 24 Dec 2000 22:01:27 GMT
From: Fireball€XL5 <isithotinhere@orisitjustme.com>
Subject: Does anyone know hoe to get sendmail to work on webprovider.com?
Message-Id: <241220001401306516%isithotinhere@orisitjustme.com>

I am trying to setup a simple mailform page using formmail.cgi, and the
script seems to be working fine, but the emails are never processed by
the server (or if they are, they go nowhere)
Supposedly, the host states that the path to sendmail is:
usr/lib/sendmail

But as I said, nothing is working. The same script runs fine on other
servers.
I have tried to get a response from their tech support but they take
forever to respond to emails...
Does anyone know anything about this host, and sendmail issues with
them?
Thanks
Mike
www.nwprints.com


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

Date: Mon, 25 Dec 2000 12:56:03 +1300
From: "Tintin" <you.will.always.find.him.in.the.kitchen@parties>
Subject: Re: Does anyone know hoe to get sendmail to work on webprovider.com?
Message-Id: <977702297.291197@shelley.paradise.net.nz>


"Fireball?XL5" <isithotinhere@orisitjustme.com> wrote in message
news:241220001401306516%isithotinhere@orisitjustme.com...
> I am trying to setup a simple mailform page using formmail.cgi, and the
> script seems to be working fine, but the emails are never processed by
> the server (or if they are, they go nowhere)
> Supposedly, the host states that the path to sendmail is:
> usr/lib/sendmail
>
> But as I said, nothing is working. The same script runs fine on other
> servers.
> I have tried to get a response from their tech support but they take
> forever to respond to emails...
> Does anyone know anything about this host, and sendmail issues with
> them?
> Thanks
> Mike
> www.nwprints.com

And just what makes you think this is a Perl question?  You clearly state
that the script is fine and runs fine on other servers.  At best it is a
sendmail question, but the query really is with your ISP and how their
system is setup.

Try in comp.mail.sendmail or change your ISP if you think their tech support
is too slow.




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

Date: Mon, 25 Dec 2000 01:25:28 GMT
From: Fireball€XL5 <fire@bahl.hot>
Subject: Re: Does anyone know hoe to get sendmail to work on webprovider.com?
Message-Id: <241220001725326443%fire@bahl.hot>

Thanks for the help
fb

In article <977702297.291197@shelley.paradise.net.nz>, "Tintin"
<you.will.always.find.him.in.the.kitchen@parties> wrote:

> comp.mail.sendmail


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

Date: Mon, 25 Dec 2000 01:42:10 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Does anyone know hoe to get sendmail to work on webprovider.com?
Message-Id: <slrn94d9gc.mbt.efflandt@efflandt.xnet.com>

On Sun, 24 Dec 2000, FireballXL5 <isithotinhere@orisitjustme.com> wrote:
>I am trying to setup a simple mailform page using formmail.cgi, and the
>script seems to be working fine, but the emails are never processed by
>the server (or if they are, they go nowhere)
>Supposedly, the host states that the path to sendmail is:
>usr/lib/sendmail

You are confused about system paths, apparently fail to test your open(),
and therefore fail to check the variable $! that would tell you why it
failed.  Sendmail is likely at the absolute path /usr/lib/sendmail, NOT
the relative path usr/lib/sendmail.  A missing slash can totally ruin your
day.

-- 
David Efflandt  efflandt@xnet.com  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: Sun, 24 Dec 2000 19:03:06 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: FAQ 5.3:   How do I count the number of lines in a file?
Message-Id: <KLr16.447$B9.189619712@news.frii.net>

In article <RF806.1255$lz1.274493@news.uswest.net>,
Jerome O'Neil <jerome.oneil@360.com> wrote:
>PerlFAQ Server <faq@denver.pm.org> elucidates:
>> This message is one of several periodic postings to comp.lang.perl.misc
>> intended to make it easier for perl programmers to find answers to
>> common questions. The core of this message represents an excerpt
>> from the documentation provided with every Standard Distribution of
>> Perl.
>> 
>> +
>>   How do I count the number of lines in a file?
>
>I don't know who maintains this, but Abigail's line count JAPH aught
>to be an answer to this as well, purely as an academic exercise.
>

Send your suggestions to perlfaq-suggestions@perl.com.  If your suggestions
take the form of a diff to the pod source file they are that much easier
to incorporate.

chris
-- 
    This space intentionally left blank


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

Date: Sun, 24 Dec 2000 07:38:21 -0800
From: Bill Moseley <usenet@hank.org>
Subject: Re: Help Bidirectional IPC with IPC::Open2
Message-Id: <MPG.14afb849b37de19098978d@news.newsguy.com>

On Sat, 23 Dec 2000 16:02:00 +0000 (UTC) David Efflandt 
(efflandt@xnet.com) remarked...
> >my ( $rh, $wh );
> 
> I think you need to assign something useful to the above variables.
> From perldoc IPC::Open2:
> 
> WARNING
>        It will not create these file handles for you.  You have
>        to do this yourself.  So don't pass it empty variables
>        expecting them to get filled in for you.

Hi David,

Time to Upgrade!

       If either reader or writer is the null string, this will
       be replaced by an autogenerated filehandle.  If so, you
       must pass a valid lvalue in the parameter slot so it can
       be overwritten in the caller, or an exception will be
       raised.

I think my test code would have bombed if this wasn't true.

If you test it on your machine do you only get one line returned and 
then does can_read() never return true after that? 


-- 
Bill Moseley


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

Date: Mon, 25 Dec 2000 02:53:41 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Help Bidirectional IPC with IPC::Open2
Message-Id: <slrn94ddmf.mbt.efflandt@efflandt.xnet.com>

On Sun, 24 Dec 2000 07:38:21 -0800, Bill Moseley <usenet@hank.org> wrote:
>If you test it on your machine do you only get one line returned and 
>then does can_read() never return true after that? 

Since I was not sure if your e-mail address is valid, I am posting what
did work for me.  Since my Open2 may be old, I used real filehandles:

client.pl:

#!/usr/bin/perl -w
use FileHandle;
use IPC::Open2;
$pid = open2(*Reader, *Writer, "./server.pl");

foreach (1..3) {
    print "\n>>$0: Sending Headers:$_\n";

    print Writer "Header-number: $_\n",
                 "Content-type: perl/test\n",
                 "Header: test\n\n";

    while ( 1 ) {
        my $buffer = <Reader>;
        chomp $buffer;
        last unless $buffer;
        print "<<$0: Read $buffer\n";
    }
    print "$0: number $_ done\n";
}
print "\n$0: All done!\n";


server.pl:

#!/usr/bin/perl -w
$|=1;
warn "In $0 pid=$$\n";

while ( 1 ) {
    my @headers = ();
    while ( <> ) {
        chomp;
        if ( $_ ) {
            warn "$0: Read '$_'\n";
            push @headers, $_;
        } else {
            foreach $header (@headers) {
                warn "$0: Sending $header\n";
                print "$header\n";
            }
            print "\n";
            last;
        }
    }
}


-- 
David Efflandt  efflandt@xnet.com  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: Mon, 25 Dec 2000 02:28:48 GMT
From: Mike Wescott <wescott@conterra.com>
Subject: Re: infinite loop
Message-Id: <ospuih44jy.fsf@eriadne.sc.rr.com>

garry@zvolve.com (Garry Williams) writes:

> On Sat, 23 Dec 2000 20:09:30 GMT, Mike Wescott wrote:
> >   break if /standard\.def/;

>  s/break/last/;

Doh!! Too much C recently.

-- 
	Mike Wescott
	wescott@conterra.com


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

Date: 25 Dec 2000 01:12:13 GMT
From: vivekvr@aol.com (Vivekvr)
Subject: making unique list of words matching a pattern
Message-Id: <20001224201213.26846.00008040@ng-cg1.aol.com>

Has anyone written a Perl (or sed or awk etc) program 
to list the unique words in a file that match a regular expression?
The words are separated by spaces. 

For example, in the input 

boy cat girl
foo.c boo.cpp goo.c hoo.cpp

I want to list strings matching "*.cpp", which would be 

boo.cpp
hoo.cpp

Vivek Rao 



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

Date: Mon, 25 Dec 2000 03:05:21 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: making unique list of words matching a pattern
Message-Id: <3A46B9E3.E572B2F3@rochester.rr.com>

Vivekvr wrote:
> 
> Has anyone written a Perl (or sed or awk etc) program
> to list the unique words in a file that match a regular expression?
> The words are separated by spaces.
> 
> For example, in the input
> 
> boy cat girl
> foo.c boo.cpp goo.c hoo.cpp
> 
> I want to list strings matching "*.cpp", which would be
> 
> boo.cpp
> hoo.cpp
> 
> Vivek Rao
How about:
   @hash{(join '',<>)=~/\b([^ ]*\.cpp)\b/gs}=1;
   @matches=keys %hash;
-- 
Bob Walton


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

Date: Sun, 24 Dec 2000 19:12:04 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Merry Christmas Pearl
Message-Id: <3A46BB04.F326B0E2@stomp.stomp.tokyo>


    Merry Christmas To All

    I Wish Each Of You A Christmas
    Graced With Warm Family Love


God's Love

Godzilla!


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

Date: 24 Dec 2000 10:55:05 -0500
From: Walt Mankowski <waltman@netaxs.com>
Subject: Re: Need help finding a space in a string with "index"
Message-Id: <87hf3tstk6.fsf@netaxs.com>

"Ryan & Treena Carrier" <ryanc@nci1.net> writes:

> Hmmmm..... "It doesn't work"......I'll explain briefly. I expect a 5 for
> output. I get a -1. Better?

A return value of -1 means the substring wasn't found.  Probably
$string isn't what you think it is.

Are you sure it really does have a space in it?  Are you running with
warnings turned on and use strict to catch any variable name typos?
Do you still get -1 when you try just running those two lines?

Walt


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

Date: 24 Dec 2000 09:33:39 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Perl guru's comments on creating nasted hashes!
Message-Id: <m1bsu1pvv0.fsf@halfdome.holdit.com>

>>>>> "Ralf" == Ralf Siedow <replynews@bigfoot.com> writes:

Ralf> Hello,
Ralf> my script does a sql-query on a database. I want the table to be stored in a
Ralf> nested hash so fields can be called like this $table{'rowname'}[0]!

Ralf> I did it like this:
Ralf> my $query_string = "SELECT * FROM phonebook";
Ralf> my $query = $dbh->prepare($query_string);
Ralf>  $query->execute;

Ralf> ## Is there a way to make this step shorter?
Ralf> my %table;
Ralf> my $table_row;
Ralf> while($table_row = $query->fetchrow_hashref)
Ralf> {
Ralf>  for(keys %{$table_row})
Ralf>  {
Ralf>   push(@{$table{$_}}, $table_row->{$_});
Ralf>  }
Ralf> }

Hmm.   You're wasting a lot of time building little row hashes
just to throw them away when you transpose the hash.  I'd suggest
something like:

  my $result = $query->fetchall_arrayref;
  my @colnames = @{$query->{NAME}}; # column names from the query
  my %table;
  for (my $i = 0; $i <= $#colnames; $i++) {
    $table{$colnames[$i]} = [map $_->[$i], @$result];
  }

If you don't know the colnames, I think there's a way to get them
from the $query after the execute.

And I'm sure with a few more minutes, I could turn that last loop
into a nested map somehow. :)

print "Just another Perl hacker,"

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: 24 Dec 2000 11:52:37 GMT
From: inwap@best.com (Joe Smith)
Subject: Re: perl.com web site vs. browsers
Message-Id: <924o25$1oaa$1@nntp1.ba.best.com>

In article <86ae9odku2.fsf@BuxTech.Com>,
Phil Eschallier  <phil@BuxTech.Com> wrote:
>I just went to www.perl.com/cpan to get updates to the CPAN modules
>I've installed on the machines here ... unfortunately, neither IE5.5
>under NT or Win2k nor Netscape 4.75 under Solaris is able to display
>the XML pages generated by the perl CPAN site.

What are you talking about?  Those are HTML pages, not XML.
Do you have a specific URL that is giving you problems?
	-Joe
--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.


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

Date: Mon, 25 Dec 2000 06:06:33 +0200
From: "Vitaly Tkachenko" <virtualvat@yahoo.com>
Subject: Re: testing if $_ is equal to some string?
Message-Id: <926h5e$64om9$1@ID-19904.news.dfncis.de>

> > if($_ eq "xxx\n"){ # Foo! }
> or if ( /xxx\\n/ )
Oh no, man :))
this way gives you compareing with string "xxx\n" in this line and never
"xxx<new_line_char>"!!!!
Use
/xxx\n/
 ... or
/^xxx\n/
to compare exactly from beginning of this string (if "xxx" is strictly whole
string)

--
/ VirtualVAT /




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

Date: 24 Dec 2000 12:00:02 -0500
From: Walt Mankowski <waltman@netaxs.com>
Subject: Re: what's the 1st line os perl script ?
Message-Id: <87bsu121rh.fsf@netaxs.com>

bconnats@bellsouth.net (cwrites) writes:

> Hello. You don't need the shebang for Windows OS.

True, but Perl will still honor any options given on the shebang
line.  For example, if you start your program with

#! perl -w

it will turn on warnings even if you don't tell it to on the command
line.

Walt


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

Date: Mon, 25 Dec 2000 05:37:00 +0200
From: "Vitaly Tkachenko" <virtualvat@yahoo.com>
Subject: Re: Where can I get CRYPT for DOS/WIN?
Message-Id: <926fdh$62dug$1@ID-19904.news.dfncis.de>

> > Where can I get some CRYPT program for DOS/WIN worked such as CRYPT in
> > UNIX?
>
> There is a crypt command in your perl software.
>
Thanx a lot, Samuel ;) But I KNOW :)))))))
It just doesn't work correctly. Look:
When I call for example
    crypt( "qwerty", "qw" )
it returns
    qwDyM1db9iOPI
What is this "qw" at the begining of crypted word??? This first two
characters always repeats string-second parameter of sub crypt(). Is it
normal????????

--
/ VirtualVAT /




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

Date: Sun, 24 Dec 2000 21:20:14 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Where can I get CRYPT for DOS/WIN?
Message-Id: <slrn94dbmu.7vk.tadmc@magna.metronet.com>

Vitaly Tkachenko <virtualvat@yahoo.com> wrote:
>> > Where can I get some CRYPT program for DOS/WIN worked such as CRYPT in
>> > UNIX?
>>
>> There is a crypt command in your perl software.
>>
>It just doesn't work correctly. 


Yes it does.


>When I call for example
>    crypt( "qwerty", "qw" )
>it returns
>    qwDyM1db9iOPI
>What is this "qw" at the begining of crypted word??? 


The salt.


>This first two
>characters always repeats string-second parameter of sub crypt(). Is it
>normal????????


    perldoc -f crypt


If there is some part of the output of that command that you
don't understand *then* post a question about it.


-- 
    Tad McClellan                          SGML consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Mon, 25 Dec 2000 04:08:13 GMT
From: fallenang3l@my-deja.com
Subject: Re: Where can I get CRYPT for DOS/WIN?
Message-Id: <926h7c$v1p$1@nnrp1.deja.com>

I know, I always get that here on my Win 98 platform with ActivePerl
build 618 (5.6.0). I was always wondering if that's normal, now I at
least know that I'm not alone :).

In article <926fdh$62dug$1@ID-19904.news.dfncis.de>,
  "Vitaly Tkachenko" <virtualvat@yahoo.com> wrote:
> > > Where can I get some CRYPT program for DOS/WIN worked such as
CRYPT in
> > > UNIX?
> >
> > There is a crypt command in your perl software.
> >
> Thanx a lot, Samuel ;) But I KNOW :)))))))
> It just doesn't work correctly. Look:
> When I call for example
>     crypt( "qwerty", "qw" )
> it returns
>     qwDyM1db9iOPI
> What is this "qw" at the begining of crypted word??? This first two
> characters always repeats string-second parameter of sub crypt(). Is
it
> normal????????
>
> --
> / VirtualVAT /
>
>


Sent via Deja.com
http://www.deja.com/


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

Date: Mon, 25 Dec 2000 05:00:01 GMT
From: "Brad Bollenbach" <bbollenbach@homenospam.com>
Subject: Re: Where to obtain the perlrtfm podpage?
Message-Id: <lvA16.55285$Z9.3383162@news1.rdc1.mb.home.com>

Great! Thanks for the link.

> Still, an early version can be found here (I inserted a newline after
> the "?" to keep the lines short):
>
> http://www.xray.mpe.mpg.de/cgi-bin/extract-mbox/perl5-porters/2000-05?
> 25048%2E957207786%40chthon
>
> --
> Rick Delaney
> rick.delaney@home.com




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

Date: 24 Dec 2000 11:07:21 -0500
From: Walt Mankowski <waltman@netaxs.com>
Subject: Re: Yesterdays Date
Message-Id: <87bsu1sszq.fsf@netaxs.com>

anmcguire@ce.mediaone.net (Andrew N. McGuire) writes:

> or you could consult the FAQ answer if you dont feel like waiting. :-)
> 
> [anm@hawk ~] man perlfaq4 | grep -A4 -B4 yesterday                    [0 ttyp1]
> 
>        The time() function returns the current time in seconds
>        since the epoch.  Take one day off that:
> 
>            $yesterday = time() - ( 24 * 60 * 60 );
> 
>        Then you can pass this to localtime() and get the
>        individual year, month, day, hour, minute, seconds values.
> 
> [anm@hawk ~]                                                          [0 ttyp1]

The FAQ goes on to warn that this simple approach doesn't handle
daylight savings time, so, depending on where you live, this might not
work for brief periods twice each year.

Consult perlfaq4 for a complete explanation and improved algorithm.

Walt


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

Date: Sun, 24 Dec 2000 21:33:41 GMT
From: Andrew N McGuire <anmcguire@my-deja.com>
Subject: Re: Yesterdays Date
Message-Id: <925q3l$ftq$1@nnrp1.deja.com>

In article <87bsu1sszq.fsf@netaxs.com>,
  Walt Mankowski <waltman@netaxs.com> wrote:
> anmcguire@ce.mediaone.net (Andrew N. McGuire) writes:
>
> > or you could consult the FAQ answer if you dont feel like waiting.
:-)
> >
> > [anm@hawk ~] man perlfaq4 | grep -A4 -B4
yesterday                    [0 ttyp1]
> >
> >        The time() function returns the current time in seconds
> >        since the epoch.  Take one day off that:
> >
> >            $yesterday = time() - ( 24 * 60 * 60 );
> >
> >        Then you can pass this to localtime() and get the
> >        individual year, month, day, hour, minute, seconds values.
> >
> > [anm@hawk
~]                                                          [0 ttyp1]
>
> The FAQ goes on to warn that this simple approach doesn't handle
> daylight savings time, so, depending on where you live, this might not
> work for brief periods twice each year.
>
> Consult perlfaq4 for a complete explanation and improved algorithm.

Err, yeah, dangit that message was supposed to be cancelled.
I was being a bit silly.

anm

--
$ENV{PAGER} = 'perl -wpe0';
system perldoc => '-t', '-F', $0;

=head1 Just Another Perl Hacker


Sent via Deja.com
http://www.deja.com/


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 5194
**************************************


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