[17317] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4739 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 27 00:05:43 2000

Date: Thu, 26 Oct 2000 21:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <972619509-v9-i4739@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 26 Oct 2000     Volume: 9 Number: 4739

Today's topics:
        #perl on EFnet <wescott@conterra.com>
    Re: Big zip files handling (Garry Williams)
    Re: Big zip files handling <ned@bike-nomad.com>
    Re: chown (Maggert)
    Re: Clean POST strings <elephant@squirrelgroup.com>
    Re: Clean POST strings <r.fraser@student.murdoch.edu.au>
    Re: How can I word wrap on STDOUT? (Tom Christiansen)
    Re: How to output to printer <elephant@squirrelgroup.com>
        in an eval, redirect STDOUT to a variable <brondsem@my-deja.com>
    Re: in an eval, redirect STDOUT to a variable (Tom Christiansen)
    Re: in an eval, redirect STDOUT to a variable <brondsem@my-deja.com>
    Re: in an eval, redirect STDOUT to a variable <jeff@vpservices.com>
    Re: LWP remote file size <tony_curtis32@yahoo.com>
        need help making a unique array list <kramer@u.arizona.edu>
    Re: need help making a unique array list <tony_curtis32@yahoo.com>
    Re: need help making a unique array list <jeff@vpservices.com>
    Re: Open URL as file <jeff@vpservices.com>
    Re: Open URL as file <davesisk@ipass.net>
    Re: Open URL as file <kims@emmerce.com.au>
        raw keyboard reading and event posting allanclarke@my-deja.com
    Re: Reading regex for s### from file <elephant@squirrelgroup.com>
    Re: socket hang <tommylebrun@yahoo.com>
    Re: Starting background process from Perl jack.dunnigan@ec.gc.ca
    Re: two dimensional arrays <mcdonabNO@SPAMyahoo.com>
        what does /warn "$x" if "$x"/ mean joechakra@my-deja.com
    Re: What's wrong with this regex? <elephant@squirrelgroup.com>
    Re: What's wrong with this regex? <friedman@math.utexas.edu>
    Re: What's wrong with this regex? <uri@sysarch.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 27 Oct 2000 02:45:24 GMT
From: Mike Wescott <wescott@conterra.com>
Subject: #perl on EFnet
Message-Id: <osbsw7huhv.fsf@eriadne.sc.rr.com>

It seems that #perl on EFnet has become "invite only". Why is that?
Not that I was a very frequent lurker, but on occasion it could
be instructive.

-- 
	Mike Wescott
	wescott@conterra.com


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

Date: Fri, 27 Oct 2000 02:29:14 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Big zip files handling
Message-Id: <_L5K5.425$Si.24992@eagle.america.net>

On 26 Oct 2000 16:55:32 GMT, Camille Sauvage <camille@fortunecity.fr> wrote:
>open IN, "-";
>while (<IN>) {
>    	nop
>}
>
>It is supposed to read on line after the other. It works (or seems to) when 
>I proceed 10 Mb compressed files, but when I attack the 1 Gb, out of memory 
>error !

$ perldoc -f nop
No documentation for perl function `nop' found
$ 

-- 
Garry Williams


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

Date: Thu, 26 Oct 2000 19:57:54 -0700
From: "Ned Konz" <ned@bike-nomad.com>
Subject: Re: Big zip files handling
Message-Id: <svhru0ivrcue75@corp.supernews.com>

In article <8FD9AF276Geindre@194.149.160.37>, "Jean-Marc"
<jmgeindre@ifrance.com> wrote:

> I've read that IO::Zlib could do as I liked but it does not seem to
> suit. If someone has got a script to do so or the name of a module, I
> would be  eternally thankfull ;-) Thank you in advance

Perhaps you should look at my Archive::Zip module, which is in CPAN.
It will allow you to read zip file members chunk by chunk.

-- 
Ned Konz
Perl homepage:  http://bike-nomad.com/perl


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

Date: Fri, 27 Oct 2000 03:52:04 GMT
From: mag@ionet.net (Maggert)
Subject: Re: chown
Message-Id: <39f8fb73.94989287@news.ionet.net>

On Tue, 10 Oct 2000 07:03:28 GMT, rgarciasuarez@free.fr (Rafael
Garcia-Suarez) wrote:


>>	I've already assumed not and am looking at using Net::FTP to
>>create the directory instead. I don't own the server and don't put too
>>much hope in the admin changing server configuration!!
>
>Strange ways to create directories. I usually use mkdir.
>
>-- 

	Yeah, except mkdir doesn't work because the server is locked
down so tight that it won't allow a perl process to create a directory
outside of the cgi-bin.
	I already figured this one out anyway. Last time I work on a
Mindspring server for sure.


MP


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

Date: Fri, 27 Oct 2000 12:07:52 +1000
From: jason <elephant@squirrelgroup.com>
Subject: Re: Clean POST strings
Message-Id: <MPG.14638e88afbb746f98985f@localhost>

Fraser wrote ..
>Trying to tidy up a Query_string from a POST method in a HTML page. Doe
>any one know how to do this. To remove all the escape characters that
>are added to the posted string, to do operations on.

there are modules that do all that jazz for you .. one that's included 
as standard with official perl distributions is CGI.pm .. you can read 
about it by typing the following at the command line

  perldoc CGI

to see more about the perldoc utility type

  perldoc perldoc

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: Fri, 27 Oct 2000 10:39:15 +0800
From: Fraser <r.fraser@student.murdoch.edu.au>
Subject: Re: Clean POST strings
Message-Id: <39F8EAD3.AF7B1BD9@student.murdoch.edu.au>

THank you for your help Jason!!!

jason wrote:

> Fraser wrote ..
> >Trying to tidy up a Query_string from a POST method in a HTML page. Doe
> >any one know how to do this. To remove all the escape characters that
> >are added to the posted string, to do operations on.
>
> there are modules that do all that jazz for you .. one that's included
> as standard with official perl distributions is CGI.pm .. you can read
> about it by typing the following at the command line
>
>   perldoc CGI
>
> to see more about the perldoc utility type
>
>   perldoc perldoc
>
> --
>   jason -- elephant@squirrelgroup.com --



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

Date: 26 Oct 2000 20:09:33 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: How can I word wrap on STDOUT?
Message-Id: <39f8e3dd$1@cs.colorado.edu>

In article <ZO2K5.176$7rc.170585600@news.frii.net>,
Chris Fedde <cfedde@fedde.littleton.co.us> wrote:
>In article <39f86ff2@cs.colorado.edu>, Tom Christiansen
><tchrist@perl.com> wrote:
>>
>>And the visual appeal of a convenient WYSIWIG layout is not to be
>>easily discarded, either.
>>
>
>One thing that has always bugged me about formats is that there is
>no obvious way to format text into a scalar or an array.  Maybe it is
>just my lack of creativity but if there is a way without tying a
>file handle or other 'wrapperization' I've missed it.  

Just man perlform and search for "swrite".

>I guess
>that's why when things get a bit beyond the scope of an awk style
>reporting program I tend to jump to Text::Wrap and it's ilk. It's
>not as pretty but it is a lot more general.

Curious.  I find it extremely less general.  And nearly useless.

--tom


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

Date: Fri, 27 Oct 2000 12:31:20 +1000
From: jason <elephant@squirrelgroup.com>
Subject: Re: How to output to printer
Message-Id: <MPG.146394031cace4cd989861@localhost>

Larry Rosler wrote ..
>In article <MPG.14636b3e144cef2498985d@localhost> on Fri, 27 Oct 2000 
>09:37:25 +1000, jason <elephant@squirrelgroup.com> says...
>> ra jones wrote ..
>> >I want to be able to send reports generated by a Perl script to a
>> >printer. One way to do this would be to get the script to write to a
>> >temporary file, then print it. Is there a system command or alternative
>> >way to output a file's contents to printer rather than screen?
>> 
>> this is system dependant .. but usually for Windows the following will 
>> work
>> 
>>   open OUTPUT, 'LPT1:' or die "Bad open: $!";
>>   print OUTPUT "What you want printed\n";
>
>Can you print on a stream opened for input?
>
>    open OUTPUT '>LPT1:' ...

ahh haa .. many apologies - thanks for checking up on me Larry

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: Fri, 27 Oct 2000 02:07:09 GMT
From: Dave Brondsema <brondsem@my-deja.com>
Subject: in an eval, redirect STDOUT to a variable
Message-Id: <8tao0a$jj2$1@nnrp1.deja.com>



I have a string that I've read from a file.  Then I eval( it.  Is there
any way to change it so that the print statements don't print to STDOUT
but rather to a string.

I must be an eval because it needs vars from the first perl program.

Right now, I change every "print " to "$content .= ".  And some more
stuff to make it work.

But I think there should be a better way.  Is there?


Thanks.

--
Dave Brondsema


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 26 Oct 2000 20:36:42 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: in an eval, redirect STDOUT to a variable
Message-Id: <39f8ea3a@cs.colorado.edu>

In article <8tao0a$jj2$1@nnrp1.deja.com>,
Dave Brondsema  <brondsem@my-deja.com> wrote:
>
>
>I have a string that I've read from a file.  Then I eval( it.  Is there
>any way to change it so that the print statements don't print to STDOUT
>but rather to a string.
>
>I must be an eval because it needs vars from the first perl program.
>
>Right now, I change every "print " to "$content .= ".  And some more
>stuff to make it work.
>
>But I think there should be a better way.  Is there?

This:

    sub forksub(&) {
        my $kidpid = open my $self, "-|";
        defined $kidpid         || die "cannot fork: $!";
        shift->(@_), exit       unless $kidpid;
        local $/                unless wantarray;
        return <$self>;
    }

    $string = 'print "This is a test"';
    $content = '';
    $content .= forksub { eval $string };
    print "Content now <$content>\n";

Produces this:

    Content now <This is a test>

However, I would suggest adjusting the stuff in the file instead.

--tom


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

Date: Fri, 27 Oct 2000 03:14:38 GMT
From: Dave Brondsema <brondsem@my-deja.com>
Subject: Re: in an eval, redirect STDOUT to a variable
Message-Id: <8taruq$mgd$1@nnrp1.deja.com>

In article <39f8ea3a@cs.colorado.edu>,
  tchrist@perl.com (Tom Christiansen) wrote:
> In article <8tao0a$jj2$1@nnrp1.deja.com>,
> Dave Brondsema  <brondsem@my-deja.com> wrote:
> >
> >
> >I have a string that I've read from a file.  Then I eval( it.  Is
there
> >any way to change it so that the print statements don't print to
STDOUT
> >but rather to a string.
> >
> >I must be an eval because it needs vars from the first perl program.
> >
> >Right now, I change every "print " to "$content .= ".  And some more
> >stuff to make it work.
> >
> >But I think there should be a better way.  Is there?
>
> This:
>
>     sub forksub(&) {
>         my $kidpid = open my $self, "-|";
>         defined $kidpid         || die "cannot fork: $!";
>         shift->(@_), exit       unless $kidpid;
>         local $/                unless wantarray;
>         return <$self>;
>     }
>
>     $string = 'print "This is a test"';
>     $content = '';
>     $content .= forksub { eval $string };
>     print "Content now <$content>\n";
>
> Produces this:
>
>     Content now <This is a test>

I get:
Can't use an undefined value as filehandle reference at test.pl line
33.  (First line of sub).  I'm running windows if it makes any
difference.  What is the $self variable?

> However, I would suggest adjusting the stuff in the file instead.

I will if I have to, but a print statement is more complex than you may
first think (see the thread "complex (for me anyway) rexexp").

> --tom
>

--
Dave Brondsema


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 26 Oct 2000 20:49:34 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: in an eval, redirect STDOUT to a variable
Message-Id: <39F8FB4E.641239CC@vpservices.com>

Dave Brondsema wrote:
> 
> I have a string that I've read from a file.  Then I eval( it.  Is there
> any way to change it so that the print statements don't print to STDOUT
> but rather to a string.

At the risk of drawing Tom's ire for suggesting a module, try:

  use IO::Scalar;
  my $str;
  my $io = tie *STDOUT, 'IO::Scalar', \$str; 
  print 'Hello, world';  # "prints" to $str                    
  undef $io;
  untie *STDOUT;
  print "\n[$str]\n";    # print to screen

-- 
Jeff


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

Date: 26 Oct 2000 22:43:14 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: LWP remote file size
Message-Id: <87snpj54q5.fsf@limey.hpcc.uh.edu>

>> On Thu, 26 Oct 2000 22:12:06 GMT,
>> "EM" <me@privacy.net> said:

> i use lwp to transfer files from one server to another
> the problem is that sometimes the server doesnt transfer
> the entire file is there a way to get the file size on
> the remote server so i can compare to the transferred
> file to see if its all there

When you get the reply from the server, look at the

    HTTP::Headers

object to get the content_length().  Then stat() the
locally saved file to compare.

(Just to be pedantic, note this isn't the same as file
size, as the remote object may be dynamically constructed
by the server.)

hth
t
-- 
Eih bennek, eih blavek.


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

Date: Thu, 26 Oct 2000 18:29:51 -0700
From: "John Kramer" <kramer@u.arizona.edu>
Subject: need help making a unique array list
Message-Id: <8taloa$fki$1@news.ccit.arizona.edu>

hello,

I'm trying to modify an array to remove any duplicate items.  The one way I
have come up with doing this is:

foreach (@array) {
     unless (map {/$_/i} @newarray) {
             push @newarray, $_;
     }
}

The actual code I am working with is a three tiered array structure that
makes this statement rather long and while it should work but it seems a bit
bulky to me.  Might there be another method that would be more compact?  I
can't help but think that the answer might lay in the pattern matching with
o modifier, but I can't seem to get anything to work on a list.

Any suggestions would be welcome.

Thanks,
John




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

Date: 26 Oct 2000 20:43:33 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: need help making a unique array list
Message-Id: <87aebr12ka.fsf@limey.hpcc.uh.edu>

>> On Thu, 26 Oct 2000 18:29:51 -0700,
>> "John Kramer" <kramer@u.arizona.edu> said:

> hello, I'm trying to modify an array to remove any
> duplicate items.  The one way I have come up with doing
> this is:

<terse>this is a FAQ,

       perldoc -q duplicate

       (perldoc perlfaq4)
</terse>

hth
t
-- 
Eih bennek, eih blavek.


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

Date: Thu, 26 Oct 2000 18:55:00 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: need help making a unique array list
Message-Id: <39F8E074.88CE403@vpservices.com>

John Kramer wrote:
> 
> I'm trying to modify an array to remove any duplicate items.  The one way I
> have come up with doing this is:
> 
> foreach (@array) {
>      unless (map {/$_/i} @newarray) {
>              push @newarray, $_;
>      }
> }
> 
> The actual code I am working with is a three tiered array structure that
> makes this statement rather long and while it should work but it seems a bit
> bulky to me.  Might there be another method that would be more compact?  

How about:

    my(@array,%is_member);
    @array = ('dog','dog','cat','bird','dog');
    @array = grep(!$is_member{$_}++, @array);
    print "@array";  # prints 'dog cat bird'

I thought of that all by myself.  And if you believe that, then you
haven't done your homework.  Your homework is:

    perldoc -q duplicate

-- 
Jeff


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

Date: Thu, 26 Oct 2000 18:04:29 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Open URL as file
Message-Id: <39F8D49D.1BFD9444@vpservices.com>

jay wrote:
> 
> I am trying to do something LIKE:
> 
> #!/usr/local/bin/perl
> open SESAME, "http://www.somedomain.com/this.gif";
> 
> while (<SESAME>)
> {
>   print "$_";
> }

That's a good thought but it only works at www.40thieves.com, not
anywhere else.

> Is there a way that I can do something like this?  Is there some perl
> module that I can use?

Yep, it's called LWP, part of the libwww bundle, get it at CPAN or
activestate.

-- 
Jeff


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

Date: Fri, 27 Oct 2000 01:02:09 GMT
From: "David Sisk" <davesisk@ipass.net>
Subject: Re: Open URL as file
Message-Id: <lu4K5.1131$G95.323537@typhoon.southeast.rr.com>

You can do it with the LWP module.  Go to www.perldoc.com, and search for
LWPcook for examples.

jay <jeano@my-deja.com> wrote in message news:8tajg2$ft5$1@nnrp1.deja.com...
> I am trying to do something LIKE:
>
> #!/usr/local/bin/perl
> open SESAME, "http://www.somedomain.com/this.gif";
>
> while (<SESAME>)
> {
>   print "$_";
> }
>
> Is there a way that I can do something like this?  Is there some perl
> module that I can use?  Thanks.
>
> -j
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.




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

Date: Fri, 27 Oct 2000 14:33:07 +1000
From: "Kim Saunders" <kims@emmerce.com.au>
Subject: Re: Open URL as file
Message-Id: <8tat1t$obt$1@thebe.syd.dav.net.au>

> #!/usr/local/bin/perl
> open SESAME, "http://www.somedomain.com/this.gif";
> 
> while (<SESAME>)
> {
>   print "$_";
> }

That would be very cool if you could do that natively in perl, open any
http or ftp url as a file, without having to with LWP or whatever the ftp
module is called (Net::FTP I spose).

KimS



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

Date: Fri, 27 Oct 2000 01:07:59 GMT
From: allanclarke@my-deja.com
Subject: raw keyboard reading and event posting
Message-Id: <8takhc$go1$1@nnrp1.deja.com>

I'm pretty new to Perl. I may have a problem that can't be done
in Perl. I need to read from the keyboard then post keypresses
to the system so that all other applications can see them. One
of the problems is that I need to do it while some other application
(a game) is running. I have started to look at Term::ReadKey but
it doesn't look like it will do it. BTW this is on Win32.

Anyone have any suggestions? Am I SOL?


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 27 Oct 2000 12:28:07 +1000
From: jason <elephant@squirrelgroup.com>
Subject: Re: Reading regex for s### from file
Message-Id: <MPG.14639344581d3cfd989860@localhost>

tigergutt2000@my-deja.com wrote ..
>I've tried to study my Perl books (Programming Perl and Perl Cookbook)
>to find a solution to my problem. Does any of you Perl athletes see
>what I'm doing wrong?
>
>1) I have some regexes stored in a text file. I read these and store
>them in a hash. From file:
>MATCHEXP=^http://www.site.com/art.asp?id=(\d+)&cat=(\d)
>REPLACEEXP=http://www.site.com/index.asp?artid=$1&category=$2
>
>2) I then wish to use these regexes to substitue a part of a URL to
>something else, like this:
>$matchexp = $hash{"MATCHEXP"};
>$replaceexp = $hash{"REPLACEEXP"};
>$newurl = $oldurl;
>$newurl =~ s#$matchexp#$replaceexp#;
>
>The urls I wish to render have this format:
>http://www.site.com/art.asp?id=2352&cat=4
>
>This construct does not insert the numbers in $1 and $2 in the newurl
>http://www.site.com/index.asp?artid=$1&category=$2

that's because only one level of interpolation happens in the 
s#$matchexp#$replaceexp# line .. ie. the $replaceexp variable is 
interpolated - but variables within that are not (otherwise - where 
would Perl stop - it could interpolate forever - and easily get into 
infinite loops)

you will need to eval the string that you create .. eg.

  eval( "\$newurl =~ s#$matchexp#$replaceexp#" );

in that the ( "" ) will interpolate the $matchexp and $replaceexp .. 
then the eval will run the resulting string - which has the $1 and $2 in 
it

>The funny (?) thing is that when changing the MATCHEXP to
>MATCHEXP=^http://www.site.com/art.asp?id=(d+)&cat=(d+)
>or
>MATCHEXP=^http://www.site.com/art.asp?id=(\[0-9]+)&cat=(\[0-9]+)
>it seems to work.

look closer .. neither of these match your string .. so they will not 
make any change to the string - if you started with

  http://www.site.com/art.asp?id=2352&cat=4

then you will have ended with the same thing (ie. no substitution at all 
will have happened)

>Why is this? I'm I just a rookie when it comes to regexes?
>Should I use qr// in some way?

no .. that's only for the match - which is actually working .. the 
problem is in the substitution where the variables are not being 
interpolated twice

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: Fri, 27 Oct 2000 01:19:07 GMT
From: T <tommylebrun@yahoo.com>
Subject: Re: socket hang
Message-Id: <8tal66$h87$1@nnrp1.deja.com>

In article <x71yx3mxbt.fsf@home.sysarch.com>,
  Uri Guttman <uri@sysarch.com> wrote:
> >>>>> "T" == T  <tommylebrun@yahoo.com> writes:
>
>   T> In article <x74s20mes8.fsf@home.sysarch.com>,
>   T>   Uri Guttman <uri@sysarch.com> wrote:
>   >> jeez, the third socket buffering problem today. turn on
autoflushing
>   T> on
>   >> the socket and use non-blocking reads.
>                         ^^^^^^^^^^^^^^^^^^
>
>   T> I am autoflushing the socket & I am using sysread to get back
the data.
>   T> Here is what I am experiencing. My script sends data to a server
&
>   T> waits for acknowledgement data to come back. The records are
sent fine.
>   T> The problem occurs when the data is sent back. I get a few bytes
& then
>   T> it seems like the server stops sending. At that point my program
is
>   T> still waiting for the rest of the record. And it waits,,,,
forever....
>
> see the marked comment above. and remember, the server also has to
flush
> its buffers for you to see the data. is it doing so? are you POSITIVE
> the server is working correctly? test it with some other know working
> client like telnet.
>
> 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
>

Yeah, the server is working. This problem doesn't happen right away.
The socket is opened the first thing every morning & stays open all
day. I usually successfully sent a few thousand records before it hangs.

Here is how I am doing the read:
### Read data from the socket
while (sysread($SOCKET, ${BYTEIN}, 1) == 1)
{
        if ( $BYTEIN ne "\x1c" )
        {
               print LOGFILE "${BYTEIN}";
        } else
        {
               print LOGFILE "${BYTEIN}";
               last;
        }
}

Thanks 4 the help.    T.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 27 Oct 2000 03:07:09 GMT
From: jack.dunnigan@ec.gc.ca
Subject: Re: Starting background process from Perl
Message-Id: <8targq$mb4$1@nnrp1.deja.com>

In article <slrn8vhf2k.ksa.mgjv@verbruggen.comdyn.com.au>,

> This is wrong. system will not return until the program it invoked
> returns[1], completes, or there is an error.
>

You're right...what I meant to post was this..

system("/somedir/someprocess &");

i.e. launch a background process and the system command returns
immediately.

Jack


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 26 Oct 2000 18:31:27 -0700
From: "Brian McDonald" <mcdonabNO@SPAMyahoo.com>
Subject: Re: two dimensional arrays
Message-Id: <zW4K5.9966$Wq1.5875597@nnrp5-w.sbc.net>


"Ren Maddox" <ren.maddox@tivoli.com> wrote in message
news:m34s20rzdj.fsf@dhcp11-177.support.tivoli.com...
>
> You probably want something like:
>
> my @authors;
> push @authors, [ $lname, $fname, $minit, $suffix, $prefix, $title,
>                  $affiliation ];
>
> though a list of hashes might be more useful:
>
> push @authors, { LNAME => $lname,
>                  FNAME => $fname,
>                  MINIT => $minit,
>                  SUFFIX => $suffix,
>                  PREFIX => $prefix,
>                  TITLE => $title,
>                  AFFILIATION => $affiliation,
>                };

Well, between your post (which really provided me with the proper solution)
and "nobull's"  (which totally deconstructed mine... and ripped it to hell)
I now have a much better understanding of how to handle the type of data I
had in mind.

Thanks for the help... both of you.

Brian






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

Date: Fri, 27 Oct 2000 03:32:24 GMT
From: joechakra@my-deja.com
Subject: what does /warn "$x" if "$x"/ mean
Message-Id: <8tat08$ndl$1@nnrp1.deja.com>

Here is a short perl script(?) I wrote to split images and it works:
    use Image::Magick;
    $fname=shift;
    print "input file=$fname\n";
    $image = new Image::Magick;
    $x=$image->Read($fname);
    warn "$x" if "$x";
    $count=0+$x;
    $of="out001";
    print "$count";


-------------------------------------------
My question what is the meaning of
    warn "$x" if "$x";
    $count=0+$x;

Is $x a string, a number, a list, or a class? warn does not produce any
output. But count prints as "2"
joe





Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 27 Oct 2000 12:40:31 +1000
From: jason <elephant@squirrelgroup.com>
Subject: Re: What's wrong with this regex?
Message-Id: <MPG.1463962a1c91e4c1989862@localhost>

David Sisk wrote ..
>$some_variable = $1 + $2/$3 if ($other_variable =~ /\d{2} \D[A-Z][a-z]{3}
>(\d*) (\d*)\/(\d*)/);
>
>The string in $other_variable looks like one of these:
>00 Nov 5 (IFQ KA-E)
>00 Nov 7 1/2 (IFQ KB-E)
>00 Nov 10 (IFQ KC-E)
>00 Nov 12 1/2 (IFQ KD-E)
>
>I'm trying to get the number in the middle (the 5, 7.5, 10, 12.5
>respectively) into $some_variable.  What's wrong with my regex?  Please post
>or email?

let's go through it

  two digits - \d{2} - followed by a space

  then a non-digit - \D - followed by a character in the range A-Z
  - [A-Z] - followed by three characters in the range a-z - [a-z]{3} -
  followed by a space

  then capturing zero or more digits - (\d*) - followed by a space

  then capturing zero or more digits - (\d*) - followed by a forward
  slash - \/ - followed by capturing zero or more digits - (\d*)

now the second group of characters is definitely not what you want

  perldoc perlre

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: Thu, 26 Oct 2000 20:50:56 -0500
From: Chas Friedman <friedman@math.utexas.edu>
Subject: Re: What's wrong with this regex?
Message-Id: <39F8DF7F.684C7202@math.utexas.edu>

David,
if
($other_variable =~ /\d{2} [A-Z][a-z]{2} (\d*) (\d*)\/(\d*)/)
{$some_variable = $1 + $2/$3;}
elsif ($other_variable=~ /\d{2} [A-Z][a-z]{2} (\d*) /)
{$some_variable = $1;}
seems to work although it is a bit ugly. I think your "\D[A-Z][a-z]{3}" section
is garbled. You want a capital
followed by 2 lower case. Also you have to match numbers like 17 1/2 or just 17.

                                             chas friedman

David Sisk wrote:

> $some_variable = $1 + $2/$3 if ($other_variable =~ /\d{2} \D[A-Z][a-z]{3}
> (\d*) (\d*)\/(\d*)/);
>
> The string in $other_variable looks like one of these:
> 00 Nov 5 (IFQ KA-E)
> 00 Nov 7 1/2 (IFQ KB-E)
> 00 Nov 10 (IFQ KC-E)
> 00 Nov 12 1/2 (IFQ KD-E)
>
> I'm trying to get the number in the middle (the 5, 7.5, 10, 12.5
> respectively) into $some_variable.  What's wrong with my regex?  Please post
> or email?
>
> Regards,
> Dave



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

Date: Fri, 27 Oct 2000 04:02:29 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: What's wrong with this regex?
Message-Id: <x7og07kk2y.fsf@home.sysarch.com>

>>>>> "DS" == David Sisk <davesisk@ipass.net> writes:

  DS> $some_variable = $1 + $2/$3 if ($other_variable =~ /\d{2} \D[A-Z][a-z]{3}
  DS> (\d*) (\d*)\/(\d*)/);

  DS> The string in $other_variable looks like one of these:
  DS> 00 Nov 5 (IFQ KA-E)
  DS> 00 Nov 7 1/2 (IFQ KB-E)
  DS> 00 Nov 10 (IFQ KC-E)
  DS> 00 Nov 12 1/2 (IFQ KD-E)

you are dividing by undef if there is no fraction. that should be a
separate check. also don't escape \ in a regex, use a different delim.

also you are matching the / in all cases. make that whole fraction
optional with non-grabbing parens.

use + instead of * as you are looking for at least one digit in places.


perl -ne 'print "$1/$2/$3\n" if m|\d\d\s+\w{3}\s+(\d+)\s+(?:(\d+)/(\d+))?|'

or to handle the fractions like you want:

	if ( m|\d\d\s+\w{3}\s+(\d+)\s+(?:(\d+)/(\d+))?| ) {

		$num = $1 ;

		$num += $2/$3 if defined( $3 ) ;
	}

i used \w for the month as it is simpler. you can make it tighter with
[a-z]{3} and the /i modifier. also i used \s+ for the whitespaces as it
can handle tabs and multiple spaces.

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: 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 4739
**************************************


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