[17126] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4538 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 6 09:05:24 2000

Date: Fri, 6 Oct 2000 06: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: <970837509-v9-i4538@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 6 Oct 2000     Volume: 9 Number: 4538

Today's topics:
    Re: beginner question <jeffp@crusoe.net>
        calculating CRC-32 of remote file? phartog@my-deja.com
    Re: calculating CRC-32 of remote file? <jeffp@crusoe.net>
        Date problem <meej@sol.dk>
    Re: Date problem (Bernard El-Hagin)
    Re: Date problem <bmaynard@voodoox.net>
    Re: DBM files don't work after upgrade <peter.howe@primark.com>
    Re: Help with CGI <flavell@mail.cern.ch>
        http_cookie not set in ms ie klooser@tech.ch
    Re: lexical for loops nobull@mail.com
        newbie struggles with slashcode aweeraman@my-deja.com
    Re: Perl utilizing DBI - Would love assistance! <ubl@schaffhausen.de>
    Re: Perl utilizing DBI - Would love assistance! (Rafael Garcia-Suarez)
        POSIX and Time::Local (Chest Rockwell)
    Re: POSIX and Time::Local (Anno Siegel)
    Re: POSIX and Time::Local (Villy Kruse)
    Re: Problems with Perl2exe ... (CDM)
    Re: Reading textfiles from client? <ubl@schaffhausen.de>
    Re: regex <jeffp@crusoe.net>
        Splitting data <vivekvp@spliced.com>
    Re: Splitting data (Bernard El-Hagin)
    Re: Splitting data <foo@bar.va>
    Re: Splitting data <news@sinus-medien.de>
    Re: Very simple question. <carvdawg@patriot.net>
    Re: Very simple question. <philipg@atl.mediaone.net>
    Re: Very simple question. <ubl@schaffhausen.de>
    Re: Win32::ChangeNotify <ZSSTL@Zeppelin.de>
    Re: Win32::ChangeNotify <carvdawg@patriot.net>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 6 Oct 2000 07:47:40 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: beginner question
Message-Id: <Pine.GSO.4.21.0010060745510.14163-100000@crusoe.crusoe.net>

On Oct 6, Larry Rosler said:

>In article <39dd0bf4.1863033@news.newsguy.com>, kcivey@cpcug.org says...
>> Larry Rosler <lr@hpl.hp.com> wrote:
>> 
>> >qw(Sun Mon Tue Wed Thu Fri Sat)[...]
>> >                       Use the numerical day of the week to extract
>> >                       the name from a list of names.  I have corrected
>> >                       the expression so it doesn't use barewords,
>> >                       which would draw a warning.
>> 
>> I think you need another set of parentheses there.
>
>I thought so also, until I tested the code without them, and it worked 
>fine.  So I saved two keystrokes, at the cost of this subthread.  :-)

Perl 5.6 rewfashioned qw/a b c d/.  It used to be:

  split ' ', 'a b c d'

at run-time, but now it's split at compile-time, and turned into a real
list

  ('a', 'b', 'c', 'd')

This is partly to prevent "qw() in scalar context" mishaps, and partly for
speed.

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/





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

Date: Fri, 06 Oct 2000 10:37:23 GMT
From: phartog@my-deja.com
Subject: calculating CRC-32 of remote file?
Message-Id: <8rka14$ul1$1@nnrp1.deja.com>

Hello coders,

I just started to learn CGI scripts, I wonder
is there a script that can download a remote file
and calculate its CRC-32?

++++++++++++++++++++++++++++++++++++++++++
An example:

  Let's say we have a file here:
    http://www.unknowdomain.com/file.zip

  I say my script the URL of that file and it
  gives me CRC-32 (in decimal: 2871377799,
  or hex: AB25BF87).

++++++++++++++++++++++++++++++++++++++++++

Or maybe there is such a utility on the web somewhere?
(I really need it...)

Thanks!

P.H.
dino.4dw.com


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


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

Date: Fri, 6 Oct 2000 07:57:10 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: calculating CRC-32 of remote file?
Message-Id: <Pine.GSO.4.21.0010060751550.14163-100000@crusoe.crusoe.net>

[posted & mailed (or tried)]

On Oct 6, phartog@my-deja.com said:

>I just started to learn CGI scripts, I wonder
>is there a script that can download a remote file
>and calculate its CRC-32?

Is a CRC-32 a 32-bit checksum?  If so...

  $csum += unpack "%32C*", $_ while <FILE>;
  $csum %= (2**32);

Getting the file from the internet is the job of LWP::Simple.  If you
want, you can outsource to some local shell utility to fetch a file off
the web.

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/





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

Date: Fri, 06 Oct 2000 12:30:02 -0000
From: IJ <meej@sol.dk>
Subject: Date problem
Message-Id: <strheaij8m6mb9@corp.supernews.com>

Hi,
Problem: $date has an output like this: 1900100.10.07, instead of the 
correct format 2000.10.07. If somebody has a ready script/suggestion for 
this please drop it to me as soon as possible.

Best regards


--
Posted via CNET Help.com
http://www.help.com/


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

Date: 6 Oct 2000 12:42:29 GMT
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: Date problem
Message-Id: <slrn8tri5q.f8v.bernard.el-hagin@gdndev25.lido-tech>

On Fri, 06 Oct 2000 12:30:02 -0000, IJ <meej@sol.dk> wrote:
>Hi,
>Problem: $date has an output like this: 1900100.10.07, instead of the 
>correct format 2000.10.07. If somebody has a ready script/suggestion for 
>this please drop it to me as soon as possible.

Why don't you show the relevant part of your script and someone will
certainly help you solve your problem. On the other hand, you can try
'perldoc -f localtime' and I guarantee that you'll find the answer
there.

Cheers,
Bernard
--
perl -le '$#="Just Another Perl Hacker"; print \Bernard'


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

Date: Fri, 6 Oct 2000 13:45:06 +0100
From: "liliafan" <bmaynard@voodoox.net>
Subject: Re: Date problem
Message-Id: <39ddc8a8$1@news.jakinternet.co.uk>

Sounds to me as though you are using concatenation instead of adding
can we see the code you are using?

-Ben
"IJ" <meej@sol.dk> wrote in message
news:strheaij8m6mb9@corp.supernews.com...
> Hi,
> Problem: $date has an output like this: 1900100.10.07, instead of the
> correct format 2000.10.07. If somebody has a ready script/suggestion for
> this please drop it to me as soon as possible.
>
> Best regards
>
>
> --
> Posted via CNET Help.com
> http://www.help.com/




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

Date: Fri, 6 Oct 2000 11:27:11 +0100
From: "Peter Howe" <peter.howe@primark.com>
Subject: Re: DBM files don't work after upgrade
Message-Id: <39ddaa56$1@primark.com>

Yes - this would seem to work.

The only difference I notice is that, although both systems are perl
5.005_03, one is built for i386 and one for i586 - so maybe byte
alignment/padding is defaulted differently.

Thanks for you help anyway.

"Trevor Ward" <tward10@jaguar.com> wrote in message
news:8rk4h1$bca8@eccws12.dearborn.ford.com...
> I have hit this problem also in creating DBM files on one machine and then
> trying to access them on the other. Have not found a solution to why this
is
> happening but ended up doing a file extract import program to take out the
> data into a text file copy that then load into a dbm file.
>
> Very useful utility programs after they have been written.
>
> also preety simple to write. So you can try this if you like.
>
> Peter Howe <peter.howe@primark.com> wrote in message
> news:39dd91ee$1@primark.com...
> > I've just upgraded my Linux system and in the process, Perl has been
> > upgraded.  I copied my whole intranet to the new machine but am finding
> that
> > the DBM files I have are no longer being read correctly (using the same
> > scripts.)
> >
> > For example,
> >
> > if (dbmopen(%projects, "/intranet/etc/projects", undef))
> > {
> >     foreach $projid (keys %projects)
> >     {
> >         print "$projects{$projid}";
> >     }
> > }
> >
> > Is coming back with nowt - but there is loads of info in the files.  Can
> > anyone explain?  PLEASE!
> > Pete
> >
> > --
> >    ----------------------
> >    Peter Howe
> > E: peterhowe@xenzero.com
> > I: http://www.xenzero.com
> >
> >
>
>




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

Date: Fri, 6 Oct 2000 12:48:59 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Help with CGI
Message-Id: <Pine.GHP.4.21.0010061227070.5093-100000@hpplus03.cern.ch>

On Fri, 6 Oct 2000, Bart Lateur wrote:

> This line:
> 
> >print "Content-type: text/html\n\n";
> 
> Looks fine to me. 

So it does!  I'm sorry, on that point I was mistaken.

However, the symptoms make it clear that the content-type header isn't
working.

> Perhaps IIS is as dummy-friendly as IE, 

I think anyone wanting to follow-up this issue would be better advised
to consult the discussions on the comp.infosystems.www.authoring.cgi
and comp.infosystems.www.servers.ms-windows groups.

(Anyone interested in learning a transferrable skill would upgrade to
Apache as a first priority, to be honest...)

> Try moving this statement to the top of the script.

I'm sceptical that it will be beneficial, to tell the truth.

I still recommend CGI.pm (which by the way includes special treatment 
for the quirks of MS servers), and reading the applicable FAQs,
especially those which offer help in troubleshooting CGI scripts.

However, based on the original poster's email to me, I would have to
conclude that any worthwhile advice offered here will only be useful
to other people.

cheers



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

Date: Fri, 06 Oct 2000 12:25:55 GMT
From: klooser@tech.ch
Subject: http_cookie not set in ms ie
Message-Id: <8rkgcd$3ap$1@nnrp1.deja.com>

Hi,

i get some problems with micorsoft IE. it's not possible to read the
cookie. The Browser set's the cokkie with correct values.then i tried
to receive the cookie with fetch CGI::Cookie.
http_cookie ENV is not set by using ms IE.

With netscape everything work fine.

use: apache 1.3.9 unix, perl 5.005_03, solaris 2.6

any idea?

thx. Kilian Looser


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


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

Date: 06 Oct 2000 12:16:02 +0100
From: nobull@mail.com
Subject: Re: lexical for loops
Message-Id: <u9lmw2cj9p.fsf@wcl-l.bham.ac.uk>

"P.Eftevik" <haf@autra.noXX> writes:

> Is this allowed/recommended  ? :
> 
> for ( $char = 'A' ;  $char lt 'G'  ;  $char++ )     {}

It is allowed but now that the behaviour of .. in for() has been
optomised most Perl hackers would write it as:

for $char ('A' .. 'F') {}

(Assuming the loop body doesn't modify $char.  If the loop body does
modify $char then use your C-style for()).

For details of how ++ and .. work with strings RTFM.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Fri, 06 Oct 2000 10:24:19 GMT
From: aweeraman@my-deja.com
Subject: newbie struggles with slashcode
Message-Id: <8rk98g$u6b$1@nnrp1.deja.com>

I am a slash newbie and I installed all the components just as they
were told in the slash installation guide along with the myriad of perl
modules from CPAN. since i had trouble getting the exact versions
mentioned i downloaded the latest ones. but at the end, after copying
the slash's version of httpd.conf to the apache conf directory and
starting apache, i get an error message as follows :

Constant subroutine XHTML_DTD redefined at /usr/lib/perl5/constant.pm
Line 175
/bin/apachectl: httpd could not be started

i run slackware 7 with apache 1.3.11 and mysql 3.22.32.

i reinstalled everything on another linux box with the same specs and i
got the same error message but the httpd daemon did not stop and i got
slash running. i had to type http://my.ip.address/index.pl to get the
correct page otherwise i got a lot of garbage. i added 'index.pl' to
the DirectoryIndex directive in the httpd.conf before the
default 'index.shtml' and it solved the problem, i am not sure if this
might introduce new problems though. i would be really really grateful
if anyone could help me out with this. i am losing sleep. thanx in
advance.


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


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

Date: Fri, 06 Oct 2000 12:50:49 +0200
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: Perl utilizing DBI - Would love assistance!
Message-Id: <39DDAE8A.542723EF@schaffhausen.de>



Adam of RWS schrieb:

> I'm an experienced programmer relatively new to CGI.  I have written a script in
> Perl.  The syntax of the script checks out.  I can't even get warnings from
> the -w switch.
> When I run the script at the command line a bunch of pretty looking HTML dumps
> out including a proper header.  The suggestions I've gotten from friends,
> coworkers, and books (Yes, I stooped that low) have led me to try the following:
>
> 1) check the header.
>     The header is immaculate.
>
> 2) flush STDOUT before doing anything else ($| = 1)
>     No result.
>
> 3) Redirect STDERR to see if I get any error messages.
>     I didn't expect this to work since I got no errors from the command line.
>     I was right, it didn't give me any errors.
>
> 4) check the server error log.
> What I got was a bunch of lines that say:
> /*my IP*/ - [/*date and time*/] "GET /*my URL*/ HTTP/1.1" 500 546
>
> I can't find any info on what the 546 means, and I can't imagine where else to
> go from here.
>
> Also, the script is in a directory that has other CGI files doing similar
> actions but aren't using the Perl DBI Module.  This script has the same rights
> as the other scripts, so I can't imagine why it won't run.
> I know the DBI Module is working because I don't get an error from the script
> that the DBI Module is not found. Not even when I run it from the command line.
>
> Any help would be massively appreciated!!!

This sounds like a problem with your headers. Could you send us the headers that
pop out
when you start the script from the command line?

Later,

malte



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

Date: Fri, 06 Oct 2000 12:47:48 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Perl utilizing DBI - Would love assistance!
Message-Id: <slrn8trisf.a3a.rgarciasuarez@rafael.kazibao.net>

Adam of RWS wrote in comp.lang.perl.misc:
>I'm an experienced programmer relatively new to CGI.  I have written a script in
>Perl.  The syntax of the script checks out.  I can't even get warnings from
>the -w switch.
>When I run the script at the command line a bunch of pretty looking HTML dumps
>out including a proper header.  The suggestions I've gotten from friends,
>coworkers, and books (Yes, I stooped that low) have led me to try the following:
>
>1) check the header.
>    The header is immaculate.
>
>2) flush STDOUT before doing anything else ($| = 1)
>    No result.
>
>3) Redirect STDERR to see if I get any error messages.
>    I didn't expect this to work since I got no errors from the command line.
>    I was right, it didn't give me any errors.
>
>4) check the server error log.
>What I got was a bunch of lines that say:
>/*my IP*/ - [/*date and time*/] "GET /*my URL*/ HTTP/1.1" 500 546
>
>I can't find any info on what the 546 means, and I can't imagine where else to
>go from here.

Looks like you're checking the server access logs, not the error logs.
546 probably means that 546 bytes have been sent to browser, and 500
that the HTTP return code was 500 (internal server error).

>Also, the script is in a directory that has other CGI files doing similar
>actions but aren't using the Perl DBI Module.  This script has the same rights
>as the other scripts, so I can't imagine why it won't run.
>I know the DBI Module is working because I don't get an error from the script
>that the DBI Module is not found. Not even when I run it from the command line.

The script does not run with the same environment from the command-line
and from within apache : the environment variables differ, the uid/gid
probably differ. This may be a cause of an error. Are the error logs
empty? It's difficult for us to help without a little code posted here.

-- 
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: Fri, 06 Oct 2000 00:57:41 GMT
From: haaaajo@removethis.dds.nl (Chest Rockwell)
Subject: POSIX and Time::Local
Message-Id: <39dd2383.97828687@news.xs4all.nl>

Hi there,

I am having some difficulties working with the Time::Local function. I
am looking for the number of quarters (15 minutes) since the year 2000
for a specific date ($tmp_uur var). 

I wrote a function in POSIX which determines the number of quarters.
But my collegue perl programmer complained about the POSIX module, it
gave some difficulties with PerlEx. 

So now I have to write one using the Time::Local function
(&maketimelocal). But when I compare results of the two functions the
maketimelocal function starts adding four quarters to the total on the
27th of march?! could anyone tell me whats the problem here?

-----

My code

------

#! /opt/bin/perl

use POSIX;
use Time::Local;
use strict;

my $tmp_uur = '200003270030';
# startdate and time
my $hae_enb = '0';
# nr of quarters before opening

print "TIMELOCAL $tmp_uur - " . ($hae_enb*15) . " = " .
(&maktimelocal(substr($tmp_uur . '0000',0,12),$hae_enb)) . "\n";
print "POSIX     $tmp_uur - " . ($hae_enb*15) . " = " .
(&maktimeposix(substr($tmp_uur . '0000',0,12),$hae_enb)) . "\n";

sub maktimelocal  {
	my ($tmp_dat,$tmp_enb) = @_;
	my $tmp_yyy = substr($tmp_dat,0,4);
	my $tmp_mnd = substr($tmp_dat,4,2);
	my $tmp_dag = substr($tmp_dat,6,2);
	my $tmp_uur = substr($tmp_dat,8,2);
	my $tmp_min = substr($tmp_dat,10,2);
	my $tmp_tst = timelocal(0,0,0,$tmp_dag,$tmp_mnd - 1,$tmp_yyy -
1900);
	return int(($tmp_tst -  946688400) / (15 * 60)) + ($tmp_uur *
4) + int($tmp_min / 15) - $tmp_enb;
}

sub maktimeposix ($) {
	my ($tmp_dat,$tmp_enb) = @_;
	my $tmp_yyy = substr($tmp_dat,0,4);
	my $tmp_mnd = substr($tmp_dat,4,2);
	my $tmp_dag = substr($tmp_dat,6,2);
	my $tmp_uur = substr($tmp_dat,8,2);
	my $tmp_min = substr($tmp_dat,10,2);
	my $tmp_tst = POSIX::mktime(0,0,0,$tmp_dag,$tmp_mnd -
1,$tmp_yyy - 1900);	
	my $tmp_kwv = int(($tmp_tst -  946688400) / (15 * 60)) +
($tmp_uur * 4) + int($tmp_min / 15) - $tmp_enb;
	return $tmp_kwv;

}
------

The results are :

TIMELOCAL 200003262345 - 0 = 8247
POSIX     200003262345 - 0 = 8247

TIMELOCAL 200003270000 - 0 = 8244
POSIX     200003270000 - 0 = 8248

TIMELOCAL 200003270030 - 0 = 8246
POSIX     200003270030 - 0 = 8250

200003262345 means

year : 2000
month : 03
monthday : 26
time : 23:45

------



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

Date: 6 Oct 2000 11:09:17 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: POSIX and Time::Local
Message-Id: <8rkbst$epc$1@lublin.zrz.tu-berlin.de>

Chest Rockwell <haaaajo@removethis.dds.nl> wrote in comp.lang.perl.misc:
>Hi there,
>
>I am having some difficulties working with the Time::Local function. I
>am looking for the number of quarters (15 minutes) since the year 2000
>for a specific date ($tmp_uur var). 
>
>I wrote a function in POSIX which determines the number of quarters.
>But my collegue perl programmer complained about the POSIX module, it
>gave some difficulties with PerlEx. 
>
>So now I have to write one using the Time::Local function
>(&maketimelocal). But when I compare results of the two functions the
>maketimelocal function starts adding four quarters to the total on the
>27th of march?! could anyone tell me whats the problem here?

[snip code]

I'm only guessing, but it looks like one of the functions is using
DST while the other isn't.  Both the amount (one hour) and the
time (a sunday in spring) seem to fit.

Anno


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

Date: 6 Oct 2000 12:01:10 GMT
From: vek@pharmnl.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: POSIX and Time::Local
Message-Id: <slrn8trfo6.80j.vek@pharmnl.ohout.pharmapartners.nl>

On 6 Oct 2000 11:09:17 -0000,
         Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:

>
>I'm only guessing, but it looks like one of the functions is using
>DST while the other isn't.  Both the amount (one hour) and the
>time (a sunday in spring) seem to fit.
>
>Anno


mktime(sec, min, hour, mday, mon, year, wday, ydayt, isdst)


Call POSIX::mktime with isdst set to -1 and it would do the "right thing"
with respect to summer time.

Been told this is required POSIX behaviour, but some systems behaves
differently.



Villy


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

Date: Fri, 6 Oct 2000 14:42:23 +0200
From: cdemaeyer1@mmm.com (CDM)
Subject: Re: Problems with Perl2exe ...
Message-Id: <8rkhcu$mq8$1@magnum.mmm.com>

go to a search engine and search on 'obfuscate perl'
should be a number of sites there...

"T. GUIRADO" <tguirado@iterra-team.com> wrote in message
news:8ri4g7$jlh$1@s1.read.news.oleane.net...
> Thanks to reply directly by Email, at vbezard@iterra-team.com
>
> Well,
>
> I've got CGI programs in PERL, and I don't want someone to be able to read
> my codes. So, I've tried Perl2exe ... It seems working well, but
sometimes,
> I have problems ...
>
> Does someone have experience with Perl2exe ??
> Does someone have another idea to make my codes unreadable?
>
> Thnaks in advance ...
>
>
> Vincent
>
>




Opinions expressed herein are my own and may not represent those of my employer.



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

Date: Fri, 06 Oct 2000 12:46:24 +0200
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: Reading textfiles from client?
Message-Id: <39DDAD81.398C6FD5@schaffhausen.de>

Bas Welvering schrieb:

> Hi,
>
> I want to make a page, with an input field on it, where visitors can select
> a textfile stored on their computer.
> Then I want to process this textfile, without uploading it, I just want the
> textfile to be stored in an array.
> Does anyone know how to do this?

If you dont want to upload anything, you are planning on doing computations
on the client side. Thus you probably dont want to use Perl for the processing

since Perl is not widely available on the client side. So, you might want to
consider to use some client side programming language like JavaScript or Java.

However, if you do that you're asking your question in the wrong newsgroup.

To save you time:
- You cant do what you want with JavaScript.
- Its possible in Java but its not really easy and you would have to request
some special
privileges from the user which an applet normally does not have.

Conclusion:
Upload the file via http put and then process it with Perl.

Later,

malte




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

Date: Fri, 6 Oct 2000 07:51:23 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: regex
Message-Id: <Pine.GSO.4.21.0010060749300.14163-100000@crusoe.crusoe.net>

[posted & mailed]

On Oct 6, Somniculosus said:

>How would you compact the following CODE into a one line regex?

>$line =~ s|{(.*?)}|<a href="$1">$1</a>|g;
>($tmp =$1) =~ s/ /+/g;
>$line =~ s|<a href="(.*?)"|<a href="http://smthg.com/$tmp"|g;

  $line =~ s!\{([^}]*)\}!
    my ($tmp = $1) =~ tr/ /+/;  # should URL-encode here maybe?
    qq(<a href="http://smthg.com/$tmp">$1</a>)
  !ge;

The /e modifier to the regex means the RHS (right-hand side) is to be
executed as Perl code.

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/





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

Date: Fri, 06 Oct 2000 12:06:15 GMT
From: vivekvp <vivekvp@spliced.com>
Subject: Splitting data
Message-Id: <8rkf7k$2dm$1@nnrp1.deja.com>

 Hello,

I have a list of delimited data like this:

BILL|$10000|555-5555|4|HOUSE|NEW YORK
CHRIS|$4000|666-6666|7|APT|BOSTON
LIU|$120000|777-7777|12|MANSION|SHANGHAI|CHINA
etx.

I want to search through the list for people in New York.  If they are
found - print the value the phone number and rent.

How do I just extract the phone number and rent.  Right now - I do a
split like this ($a,$b,$c,$d,$e,$f,$g)=split(/|/,$line).  But what if I
had 200 fields?

I know how to open and read a file:

#!/usr/bin/perl
open (CS,"choose.school");
print STDOUT "What school?:";
$input = <STDIN>;
chomp $input;
while($line=<CS>) {
chomp $line;
($a,$b,$c,$d,$e,$f)=split(/|/,$line);
if ($line =~/$input/) {
        print "$a $b $c $f \n";
        }
}
close (CS);

Any help?

Thanks,

V
--
He who fights and runs away, lives to run another day!


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


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

Date: 6 Oct 2000 12:38:14 GMT
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: Splitting data
Message-Id: <slrn8trhtp.f8v.bernard.el-hagin@gdndev25.lido-tech>

On Fri, 06 Oct 2000 12:06:15 GMT, vivekvp <vivekvp@spliced.com> wrote:
> Hello,
>
>I have a list of delimited data like this:
>
>BILL|$10000|555-5555|4|HOUSE|NEW YORK
>CHRIS|$4000|666-6666|7|APT|BOSTON
>LIU|$120000|777-7777|12|MANSION|SHANGHAI|CHINA
>etx.
>
>I want to search through the list for people in New York.  If they are
>found - print the value the phone number and rent.
>
>How do I just extract the phone number and rent.  Right now - I do a
>split like this ($a,$b,$c,$d,$e,$f,$g)=split(/|/,$line).  But what if I
>had 200 fields?

As I understand it the first four fields in each line are always
name|value|number|rent and the last is the city. Since you're not interested
in everything that's in between you can try:

(split '|', $line)[-1] to get the city name,
(split '|', $line)[0]  to get the first name,
(split '|', $line)[1]  to get the value,
(split '|', $line)[2]  to get the phone number, and, last but not least,
(split '|', $line)[3]  to get the rent.

This way you don't have to worry about how many fields are in each line.

Cheers,
Bernard
--
perl -le '$#="Just Another Perl Hacker"; print \Bernard'


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

Date: Fri, 06 Oct 2000 14:49:35 +0200
From: Marco Natoni <foo@bar.va>
Subject: Re: Splitting data
Message-Id: <39DDCA5F.A3F719DC@bar.va>

Bernard,

Bernard El-Hagin wrote:
>> I have a list of delimited data like this:
>> BILL|$10000|555-5555|4|HOUSE|NEW YORK
>> CHRIS|$4000|666-6666|7|APT|BOSTON
>> LIU|$120000|777-7777|12|MANSION|SHANGHAI|CHINA
>> etx.
>> I want to search through the list for people in New York.  If 
>> they are found - print the value the phone number and rent. How do 
>> I just extract the phone number and rent.  Right now - I do a
>> split like this ($a,$b,$c,$d,$e,$f,$g)=split(/|/,$line).  But what 
>> if I had 200 fields?
> As I understand it the first four fields in each line are 
> always name|value|number|rent and the last is the city. Since 
> you're not interested in everything that's in between you can 
> try:
> (split '|', $line)[-1] to get the city name,
> (split '|', $line)[0]  to get the first name,
> (split '|', $line)[1]  to get the value,
> (split '|', $line)[2]  to get the phone number, and, last but 
> not least,
> (split '|', $line)[3]  to get the rent.
> This way you don't have to worry about how many fields are in 
> each line.

  Although the list-context usage of a Perl function could often result
in a smart code style, I think that *five* calls to /split/ with the
same parameter seems excessive, expecially regarding CPU's time
consumption.  Having decided to use numerical indexing for the fields,
why do not use a named array?

<code>
	@data=split /\|/,$line;
	$city_name=$data[-1];	# and so on...
</code>

	
	Best regards,
		Marco


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

Date: Fri, 06 Oct 2000 14:47:23 +0200
From: Christian =?iso-8859-1?Q?R=FCggeberg?= <news@sinus-medien.de>
Subject: Re: Splitting data
Message-Id: <39DDC9DB.D7C117B3@sinus-medien.de>

Hi,

you also can use this:
@newlist = split(/|/,$line)

 ...and then you can get each item like this:
$phonenumber = $newlist[12];

I think you don't have 200 different items in this list,
if it is so you could better use a database-file like
csv. It is easy to use....

bye,
Christian

vivekvp schrieb:

>  Hello,
>
> I have a list of delimited data like this:
>
> BILL|$10000|555-5555|4|HOUSE|NEW YORK
> CHRIS|$4000|666-6666|7|APT|BOSTON
> LIU|$120000|777-7777|12|MANSION|SHANGHAI|CHINA
> etx.
>
> I want to search through the list for people in New York.  If they are
> found - print the value the phone number and rent.
>
> How do I just extract the phone number and rent.  Right now - I do a
> split like this ($a,$b,$c,$d,$e,$f,$g)=split(/|/,$line).  But what if I
> had 200 fields?
>
> I know how to open and read a file:
>
> #!/usr/bin/perl
> open (CS,"choose.school");
> print STDOUT "What school?:";
> $input = <STDIN>;
> chomp $input;
> while($line=<CS>) {
> chomp $line;
> ($a,$b,$c,$d,$e,$f)=split(/|/,$line);
> if ($line =~/$input/) {
>         print "$a $b $c $f \n";
>         }
> }
> close (CS);
>
> Any help?
>
> Thanks,
>
> V
> --
> He who fights and runs away, lives to run another day!
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.



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

Date: Fri, 06 Oct 2000 06:15:58 -0400
From: H C <carvdawg@patriot.net>
Subject: Re: Very simple question.
Message-Id: <39DDA65E.1E494FAB@patriot.net>

> Can I call a perl script from another perl script?

Yes.

> Is so... how?

The system() call...using backticks (`)...on Win32 systems, you
can use the Win32::Process module...



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

Date: Fri, 06 Oct 2000 11:24:12 GMT
From: "Philip Garrett" <philipg@atl.mediaone.net>
Subject: Re: Very simple question.
Message-Id: <wDiD5.20322$cW3.4040034@typhoon.southeast.rr.com>

Tim Cockle <T.Cockle@staffs.ac.uk> wrote in message
news:39DDA294.FD30BDE6@staffs.ac.uk...
> Can I call a perl script from another perl script?
>
> Is so... how?

Generally you want do() or require(), since neither start a new interpreter.
For calling other kinds of executables, you can use system(), exec(), ``
(backticks), and qx().

perldoc -f do

hth,
p




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

Date: Fri, 06 Oct 2000 14:06:24 +0200
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: Very simple question.
Message-Id: <39DDC041.52F22A57@schaffhausen.de>

Tim Cockle schrieb:

> Can I call a perl script from another perl script?
>
> Is so... how?
>

Maybe "require $some_perlscript_filename"
ist what you are looking for. If so, watch out
for namespace conflicts.

malte




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

Date: Fri, 06 Oct 2000 14:33:50 +0200
From: ZSSTL <ZSSTL@Zeppelin.de>
Subject: Re: Win32::ChangeNotify
Message-Id: <39DDC6AE.F5BDA2F1@Zeppelin.de>

H C schrieb:

> NT 4.0 SP6a, ActiveState Perl build 618
>
> Problem:  Code exits after first change....such as a file deleted or
> added, or a
>                file size change..
>
> Code:
> my $watch = new Win32::ChangeNotify($self->{monitor_dir}, 0,
>       FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_SIZE );
>
>  if ($watch) {
>   $change = $watch->wait(INFINITE);
>   if ($change) {
>    print "Change Occurred!\n";
>    $watch->reset();
>   }
>
>  }
>  else {
>   $self->{error} = "Could not create ChangeNotify object for
> $self->{monitor_dir}";
>  }
>
> Any thoughts?
>
> And, yes, Dave, I did take a look at DirMon.pl....  ;-)

Hi again HC,

your code works right: After the first change of a file $change gets
true, prints out the messages an ends the if block.
If you want to have in infinite loop, you can change
        if ($watch)
to
        while ($watch)

Greetings, Tom



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

Date: Fri, 06 Oct 2000 07:10:40 -0400
From: H C <carvdawg@patriot.net>
Subject: Re: Win32::ChangeNotify
Message-Id: <39DDB330.A2C9E5D2@patriot.net>

Tom,

Thanks!  After reviewing the docs and other code multiple times, I assumed
that
the reset() method just did that.

Your answer is the best one I've seen!  Thanks!

> your code works right: After the first change of a file $change gets
> true, prints out the messages an ends the if block.
> If you want to have in infinite loop, you can change
>         if ($watch)
> to
>         while ($watch)



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

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


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