[18806] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 974 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 24 03:10:46 2001

Date: Thu, 24 May 2001 00:05:12 -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: <990687911-v10-i974@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 24 May 2001     Volume: 10 Number: 974

Today's topics:
    Re: about combining lines of a call record file... <c_clarkson@hotmail.com>
        Anyone get setting the environment to work? <harryyu@students.uiuc.edu>
    Re: Anyone get setting the environment to work? <tony_curtis32@yahoo.com>
    Re: Anyone get setting the environment to work? <postmaster@god.edu>
    Re: Anyone get setting the environment to work? <smash@floodbox.com>
    Re: Array slice: how about the remainder? <krahnj@acm.org>
    Re: Array slice: how about the remainder? <godzilla@stomp.stomp.tokyo>
        Capturing STDERR in backticked cmd (in W98) <mnemotronic@mind\no-spam/spring.com>
    Re: CGI with conditional GET <goldbb2@earthlink.net>
    Re: converting characters in email <troyr@vicnet.net.au>
    Re: cookie expiry <goldbb2@earthlink.net>
    Re: cookie expiry (Randal L. Schwartz)
    Re: Downloading images with HTTP/LWP libraries <goldbb2@earthlink.net>
    Re: easiest way to find no. of keys in a hash (Mark Jason Dominus)
    Re: File::Path::rmtree under -T (was Re: unlinking file <webmaster@webdragon.unmunge.net>
    Re: fork <goldbb2@earthlink.net>
    Re: fork (Gwyn Judd)
        Help:string match u518615722@spawnkill.ip-mobilphone.net
    Re: Help:string match <john@axissite.com>
    Re: Help:string match <krahnj@acm.org>
    Re: Is it possible to find the position of a mismatch u <goldbb2@earthlink.net>
    Re: Module DB_File on NT <rebelvideo@hotmail.com>
        need regex help please <robert@quantum-radio.net.au>
    Re: need regex help please <bart.lateur@skynet.be>
        Recognize a number <Tim.Lauterborn@gmx.de>
    Re: Recognize a number <wyzelli@yahoo.com>
    Re: Recognize a number <pne-news-20010524@newton.digitalspace.net>
    Re: sorting a scrolling_list() (Wyatt R Johnson)
    Re: url parsing <goldbb2@earthlink.net>
    Re: wwwboard.pl - Taint and Use Strict <AgitatorsBand@yahoo.com>
    Re: wwwboard.pl - Taint and Use Strict <AgitatorsBand@yahoo.com>
    Re: wwwboard.pl - Taint and Use Strict <godzilla@stomp.stomp.tokyo>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 23 May 2001 22:07:49 -0500
From: "Charles K. Clarkson" <c_clarkson@hotmail.com>
Subject: Re: about combining lines of a call record file...
Message-Id: <0C1ECD88C30CE96D.8008D731E8E4FED6.55914D7F0782711F@lp.airnews.net>

Todd Nathan <tnathan@midwayisland.net> wrote:
: Hi,
:
: How would i write a Perl script to combine the lines of a Call Record
: into one line...?  Thanks, and you are welcome to get a hold of me
: directly, I really appreciate your help!!!
:
: \t
:
: Sample of call record data follows...
:
    [snipped data]

    I just wrote a similar sub this morning for a beginner group
on Yahoo:

sub format_file ($$) {
    my $line_start_re = shift;
    my $file_name = shift;
    my @formatted;
    open my $fh, $file_name or die "Cannot open $file_name: $!";
        # first line
        chomp (my $previous = <$fh>);
        while (my $current = <$fh>) {
            # skip blank lines
            next if $current =~ /^\s*$/;
            chomp $current;
            if ( $current !~ /$line_start_re/ ) {
                $previous .= $current;
            } else {
                push @formatted, $previous;
                $previous = $current;
            }
        }
        # get the last line
        push @formatted, $previous;

    return @formatted;
}

my @data = format_file qr/^CR/, 'in.txt';
print join "\n", @data;


HTH,
Charles K. Clarkson







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

Date: Wed, 23 May 2001 20:15:31 -0500
From: Harry Yu <harryyu@students.uiuc.edu>
Subject: Anyone get setting the environment to work?
Message-Id: <Pine.GSO.4.21.0105232013220.6114-100000@glsn7.ews.uiuc.edu>

Hello,
I know there has been 2 postings about setting environments in UNIX, and
most people said it can't be done however the perl.com website said
something about trying to do a eval of it, was anyone successful in
setting environment variables.  If so, please do tell, either in the
newsgroup or e-mail me at harryyu@uiuc.edu.

Thanks
Harry



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

Date: 23 May 2001 20:37:03 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Anyone get setting the environment to work?
Message-Id: <87snhvcytc.fsf@limey.hpcc.uh.edu>

>> On Wed, 23 May 2001 20:15:31 -0500,
>> Harry Yu <harryyu@students.uiuc.edu> said:

> Hello, I know there has been 2 postings about setting
> environments in UNIX, and most people said it can't be
> done however the perl.com website said something about

It can't be done in the literal sense of a child process
modifying the environment of its parent.

> trying to do a eval of it, was anyone successful in
> setting environment variables.

You make the perl program output text to stdout, which
when the shell evaluates it, sets the environment
variables.

Simple example, "pp" is the perl program, which contains:

    #!/usr/bin/perl -w
    print "COLUMNS=80; export COLUMNS\n";
    print "ROWS=24; export ROWS\n";

Thus the program outputs:

    $ ./pp
    COLUMNS=80; export COLUMNS
    ROWS=24; export ROWS

Those are commands that the shell understands.  Now
capture the output instead and let the shell evaluate it:

    $ eval `./pp`

voila'!  Of course, you probably want the perl program to
be more intelligent about which shell is the calling
parent process, as the syntax for setting environment
variables varies between Bourne- and C-shell derivatives.
Exercise for the reader...

This is how the "resize" program works BTW.

hth
t
-- 
Just reach into these holes.  I use a carrot.


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

Date: Wed, 23 May 2001 18:47:19 -0700
From: /dev/null <postmaster@god.edu>
Subject: Re: Anyone get setting the environment to work?
Message-Id: <3B0C6827.2D17E80@god.edu>

At 20:15 -0500 on Wed, 23 May 2001, Harry Yu wrote:
> I know there has been 2 postings about setting environments in UNIX, and
> most people said it can't be done however the perl.com website said
> something about trying to do a eval of it, was anyone successful in
> setting environment variables.  If so, please do tell, either in the
> newsgroup or e-mail me at harryyu@uiuc.edu.

I haven't read the posts to which you refer, but I have written a
Perl program which outputs variable definitions to stdout, which in
turn can be eval'd in shells and/or shell start up files.

Check out:

  http://www.gerasimov.net/~alban/construct_var_defns

It contains the program and an explanation of how it works.

David
--
David Alban
extasia "@" mindspring "." com
Live in a world of your own, but always welcome visitors.


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

Date: Wed, 23 May 2001 22:45:10 -0400
From: "smash" <smash@floodbox.com>
Subject: Re: Anyone get setting the environment to work?
Message-Id: <Zy_O6.2813$i25.369180@news20.bellglobal.com>

It is sort if similar, I just get my perl programs to write to a file, then
all the rest use that.

"Harry Yu" <harryyu@students.uiuc.edu> wrote in message
news:Pine.GSO.4.21.0105232013220.6114-100000@glsn7.ews.uiuc.edu...
> Hello,
> I know there has been 2 postings about setting environments in UNIX, and
> most people said it can't be done however the perl.com website said
> something about trying to do a eval of it, was anyone successful in
> setting environment variables.  If so, please do tell, either in the
> newsgroup or e-mail me at harryyu@uiuc.edu.
>
> Thanks
> Harry
>




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

Date: Thu, 24 May 2001 02:42:29 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Array slice: how about the remainder?
Message-Id: <3B0C7529.A1EBADC8@acm.org>

Chris Stith wrote:
> 
> Since the OP asked for a clear way to solve his problem and
> the thread switched to discussion of efficient ways to solve
> it, some of the code posted was intended to be clear but not
> necessarily the most efficient. Therefore, I'm sure some of
> the benchmarks below reflect this. A low score on this
> benchmark, therefore, shouldn't be taken as a comment on the
> abilities of the programmer who posted the code.

While this is all well and good, did you test that the code produced the
_correct_ answer as well? According to the op's post:

> I've been asked a quite interesting question.
> 
> my @array = <NAMELIST>;
> my @chosen = (0,3,5,7,21,35,63,66,68);
> my @go_picnic = @array[@chosen];  # those who are chosen go picnic
> my @stay_home = @array[???????];  # those who are not chosen stay home
> 
> It's convinent to have array slice syntax to get partial of an array.
> But what about the remainder (also partial of the array)?

Therefore after dividing the contents of @array into @go_picnic and
@stay_home you shouldn't gain or lose any people. In other words @array
== ( @go_picnic, @stay_home ).
According to my tests only nobull's, MJD's, and mine produced the
correct results (I couldn't test Joe's as I don't have 5.6)
If you just want fast code that produces random or nonexistant results I
can do that too. :-)


John
-- 
use Perl;
program
fulfillment


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

Date: Wed, 23 May 2001 20:43:21 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Array slice: how about the remainder?
Message-Id: <3B0C8359.9EB6EBC2@stomp.stomp.tokyo>

John W. Krahn wrote:
 
> Chris Stith wrote:

(snipped)

> According to my tests only nobull's, MJD's, and mine produced the
> correct results (I couldn't test Joe's as I don't have 5.6)
> If you just want fast code that produces random or nonexistant results I
> can do that too. :-)


I exhaustively tested four methods written by four authors,

Joe Schaefer
Mark Jason Dominus
Ren Maddox
Godzilla!

All work perfectly with Joe's being overall the quickest
in my personal opinion. My tests were rigorous and used
conditions exceeding the original parameters.

Chris Stith tested the same codes along with codes written
by himself, Anno Siegel and NoBull. There is no indication
of any problems in Chris Stith's article.

Perhaps your bruised ego is speaking on your behalf?


Godzilla!


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

Date: Wed, 23 May 2001 22:30:14 -0600
From: pt <mnemotronic@mind\no-spam/spring.com>
Subject: Capturing STDERR in backticked cmd (in W98)
Message-Id: <3B0C8E56.832893A6@mindspring.com>

    I'm trying to redirect STDERR to STDOUT so that I can capture both
STDERR and STDOUT output of a backticked command.  I've tried the
suggested:

@Results = `$cmd 2>&1` ;

    I don't understand how that would work under Windows ... The I/O
redirection looks like a unixy kinda thing.

    My idea is:

{
   local *STDERR = *STDOUT ;
   @Results = `$cmd` ;
}

    This works when "$cmd" names an EXE with params (i.e. "get blah.blah
*.??v"), but not when "$cmd" is a BATCH file which itself runs
executables (specifically, various cross-compiling tools from Tasking
 .... formerly BSO).  When running the BATCH I just get the STDOUT.
STDERR still goes to the console.
    Environment is W98SE running from a DOS window with ActiveState.





Remove the obvious anti-spam to reply.


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

Date: Wed, 23 May 2001 23:25:12 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: CGI with conditional GET
Message-Id: <3B0C7F18.1DDBD8E6@earthlink.net>

nobull@mail.com wrote:
> 
> Benjamin Goldberg <goldbb2@earthlink.net> writes:
> 
> > The http 1.0 standard descripes how a conditional GET can be done,
> > using an if-modified-since field in the request header.
> >
> > If I'm writing a CGI which uses GET (not post), and generates all
> > data from it's parameters (no external files, nothing which comes
> > from outside the script), then I always want to respond "304 not
> > modified" in response to a request that has an if-modified-since
> > header, since the requester obviously has whatever it is that I
> > might send him (unless the script changes).  How do I test for the
> > existance of this header?
> 
> This has very little to do with Perl.  For the most part HTTP request
> headers are passed CGI scripts as upcased environment variables with
> an 'HTTP_' prefix and all '-' tanslated to '_'.  In Perl they can be
> accessed directly via %ENV or more neatly via CGI.pm's http() method.

Thanks.  The documentation on www.perldoc.com does not mention the
http() method.  The last item listed there for fetching environment
variables is request_method().  Some other documentation which I found
via google showed content_type(), http() and https() methods, listed
after request_method().  I guess perldoc.com isn't exactly up to date,
huh?

-- 
Customer: "I would like to try on that suit in the window."
Salesman: "Sorry sir, you will have to use the dressing room."


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

Date: Thu, 24 May 2001 12:24:58 +1000
From: "Troy Boy" <troyr@vicnet.net.au>
Subject: Re: converting characters in email
Message-Id: <Zi_O6.3237$Ld4.142818@ozemail.com.au>

> > s/&#8220;/\'/g
> >
> > that won't work
>
> Why not?
Sorry i didn't write that properly

where $var contains &#8220; ## well it contains the smartquote, whether it
gets equivalated to that is another thing

$var=~ s/&#8220;/\'/g





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

Date: Wed, 23 May 2001 22:45:04 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: cookie expiry
Message-Id: <3B0C75B0.452284B@earthlink.net>

Randal L. Schwartz wrote:
> 
> >>>>> "Troy" == Troy Boy <troyr@vicnet.net.au> writes:
> 
> Troy> Time passes..........The user hits on a log out button and the
> Troy> same code is called..but the expires variable gets reset to '1s'
> Troy> .My problem is...that it doesn't take this into account..and
> Troy> keeps the cookie active till the 2 minutes have passed.
> 
> Troy> Has anyone come across this problem..?
> 
> It is not safe to rely on "removing a cookie" as a "logout mechanism".
> The browser is free to ignore your removal attempts, since setting or
> clearing a cookie is just a suggestion, not a demand.

What about changing the contents of a cookie?  Have a cookie named
"logged_in" with a value of either "1" or "0".  When the user clicks a
logout button, re-issue a new logged_in cookie with value "0".  Unless
the browser's cookies are very broken, you can expect that this override
the old value of logged_in.

This would result in your having two cookies, "sid" and "logged_in". 
You might be able to change it to one cookie, be assigning "-1" or
somesuch to "sid" to represent the user being logged out.

> The cookie should be merely a key to a server-side database that has
> the real "logged in" state.  Set your server-side database to "logged
> out", and ignore the cookie after that.

It might be preferable to have as little data on the server as possible,
especially if you have a disk quota.  Also... how long does the "logged
out" entry in the server-side database persist?  If *I* were doing it, I
would probably *delete* the database entry when the client logs out, or
somesuch.

-- 
Customer: "I would like to try on that suit in the window."
Salesman: "Sorry sir, you will have to use the dressing room."


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

Date: 23 May 2001 22:30:07 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: cookie expiry
Message-Id: <m1n18371r4.fsf@halfdome.holdit.com>

>>>>> "Benjamin" == Benjamin Goldberg <goldbb2@earthlink.net> writes:

Benjamin> What about changing the contents of a cookie?  Have a cookie
Benjamin> named "logged_in" with a value of either "1" or "0".  When
Benjamin> the user clicks a logout button, re-issue a new logged_in
Benjamin> cookie with value "0".  Unless the browser's cookies are
Benjamin> very broken, you can expect that this override the old value
Benjamin> of logged_in.

Again, a request to "change the cookie" is merely a request.  Why
continue to trust a cookie which is coming from user side, when you
already know the state change server-side.  Delete your authorization!
Don't trust the cookie any more!

-- 
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: Thu, 24 May 2001 01:30:18 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Downloading images with HTTP/LWP libraries
Message-Id: <3B0C9C6A.CAA921F3@earthlink.net>

Robert Hughes wrote:
> 
> "Bob Walton" <bwalton@rochester.rr.com> wrote in message
> news:3AF23254.628CEF8D@rochester.rr.com...
[snip]
> Is it possible to retrieve an html file and the embedded images with a
> single HTTP request?

Well, sort of.  You can use a keep-alive type connection, and perform
multiple requests over the same connection.  Since for most users, the
longest part of retrieving an http object is the connect, not the actual
downloading, this can speed things up significantly.

However, this is still multiple requests.  You ask for the first
document, passing a "connection: keep-alive" header along with
everything else, and then read the html, and parse it to learn the URL
of the image, then send another request (for the path from that URL),
read the image, and then close the connection.

However, I don't see why you are downloading the html file, unless the
URL of the image changes from time to time.

-- 
Customer: "I would like to try on that suit in the window."
Salesman: "Sorry sir, you will have to use the dressing room."


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

Date: Thu, 24 May 2001 06:45:39 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: easiest way to find no. of keys in a hash
Message-Id: <3b0cae13.66f4$1b3@news.op.net>

In article <tcYO6.15120$9D5.1302415@newsread2.prod.itd.earthlink.net>,
R <smrtalec@nospam.earthlink.net> wrote:
>
>
>what is the easiest way to find the number of keys ( entries) in a hash ?

        $n = keys %hash;

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: 24 May 2001 02:18:14 GMT
From: "Scott R. Godin" <webmaster@webdragon.unmunge.net>
Subject: Re: File::Path::rmtree under -T (was Re: unlinking files under -T)
Message-Id: <9ehr16$j9o$0@216.155.32.217>

In article <3b0c45ba.33605873@news.rmi.net>,
 posting.account@lynxview.com (William Herrera) wrote:

 | On 23 May 2001 20:29:50 GMT, "Scott R. Godin" 
 | <webmaster@webdragon.unmunge.net>
 | wrote:
 | 
 | > | >        unlink "$output_path$oldfile"; #older than 24 hours
 | > | >
 | > | >I get an "Insecure dependency" warning about the unlink. Now, 
 | > | >none of this information is user-generated, so I don't quite 
 | > | >understand why I get a warning of this nature unless it's 
 | > | >because ANY unlink operation is considered unsecure (which 
 | > | >seems to be the case, from my perusal of perlsec.pod).
 | > | 
 | > | I'd claim that filenames read off from directory are the reason 
 | > | for that insecure dependency. As your program doesn't actually 
 | > | know what generated the filenames it's reading off the 
 | > | directory, perl throws the "insecure dependency" at you.
 | >
 | >So is this something I can then clean up with the simple sort of 
 | >regex solution proposed in the depths of perlsec.pod ? 
 | 
 | Yes, you can. I suggest a regex that gets rid of pipes and such so as to
 | exclude bizarre side effects.

It's working, finally. Thanks additionally to Mark for pointing out the 
two-pronged nature of the taintedness with regards to unlinking files, 
which wasn't totally clear from the perlsec documentation. 

<grin> this was the final step in a looooong process, which means it's 
ready to go live at long last. :D yeehaw!

 | The problem I have had in the past is in using File::Path::rmtree. Is there
 | _any_ way to use that function with taint checking enabled?

I haven't experimented with that module myself, so unfortunately I can 
offer you no advice there. :(
 
 | ---

^ that should be two --'s with a space after, like "-- ", or else it 
doesn't get parsed properly as a .sig by newsreading software. Just FYI.

 | The above from: address is spamblocked. Use wherrera (at) lynxview (dot) com 
 | for the reply address.

-- 
unmunge e-mail here:
#!perl -w
print map {chr(ord($_)-3)} split //, "zhepdvwhuCzhegudjrq1qhw"; 
# ( damn spammers. *shakes fist* take a hint. =:P )


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

Date: Wed, 23 May 2001 22:21:19 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: fork
Message-Id: <3B0C701F.59A26A56@earthlink.net>

Mark Jason Dominus wrote:

I would love if someone could explain to me what this sig does (besides
the obvious fact of print ing out "Just another Perl / Unix hacker").

> @P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
> @p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
> ($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
> close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print

Maybe I should try and make a flowchart? :)

-- 
Customer: "I would like to try on that suit in the window."
Salesman: "Sorry sir, you will have to use the dressing room."


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

Date: Thu, 24 May 2001 05:56:31 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: fork
Message-Id: <slrn9gp8ke.kbe.tjla@thislove.dyndns.org>

"Mein Lufkissenfahrzeug ist voller Aale"
said Benjamin Goldberg (goldbb2@earthlink.net) in 
<3B0C701F.59A26A56@earthlink.net>:
>Mark Jason Dominus wrote:
>
>I would love if someone could explain to me what this sig does (besides
>the obvious fact of print ing out "Just another Perl / Unix hacker").
>
>> @P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
>> @p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
>> ($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
>> close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print

It is the most convoluted piece of code I've ever read in any language.
Normally I don't much like obfuscated code since as a rule it tends to
rely more on using horrible syntax and strange variable names to hide
it's true purpose. The above piece of code is one of the few that
impressed me with the fact that even once you look at it, with helpful
variable names and comments, it is still difficult to understand :) This
comes from the fact that the algorithm is even more obfuscated than the
code. There is an explanation on his webpage somewhere, which offhand I don't
remember.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
The most disagreeable thing that your worst enemy says to your face does
not approach what your best friends say behind your back.
		-- Alfred De Musset


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

Date: Thu, 24 May 2001 01:56:41 GMT
From: u518615722@spawnkill.ip-mobilphone.net
Subject: Help:string match
Message-Id: <l.990669401.1582244873@adsl-151-197-234-248.phila.adsl.bellatlantic.net>

We have hundreds of scripts in directory dba 
and subdirectory.  In it, there is one line 
we need to change
old: string= user\@mailserver1.com
new: string= user\@mailserver2.down.net

instead of change all those scripts one by one, 
I wrote a perl command line try to do this in one shot.

perl -pi.bak -e "s/user\@mailserver1.com/user\
@mailserver2.down.net" `find ./dba/ "*" -print`

maybe because of the escape issue, this did not work, 
so I tried 
perl -pi.bak -e "s/user\\@mailserver1.com/user\\
@mailserver2.down.net" `find ./dba/ "*" -print`

and 
perl -pi.bak -e "s/user\\\@mailserver1.com/user\\\
@mailserver2.down.net" `find ./dba/ "*" -print`

none of them worked.

Is there any better way of doing it or I have to change the script
one by one, look through all the files directory after directory?

Thanks
 



-- 
Sent by dbadba62 from hotmail subpart  from com
This is a spam protected message. Please answer with reference header.
Posted via http://www.usenet-replayer.com/cgi/content/new


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

Date: Thu, 24 May 2001 03:33:49 GMT
From: "John Baleshiski" <john@axissite.com>
Subject: Re: Help:string match
Message-Id: <xi%O6.23172$v5.1881995@news1.rdc1.ct.home.com>

I'm not sure about the one-liners, but this is what I did:

$s = "user\@mailserver1.com";
print $s."\n";
$s =~ s/user\@mailserver1.com/user\@mailserver2.down.net/gs;
print $s
[F6]

It printed the following:
user@mailserver1.com
user@mailserver2.down.net

<u518615722@spawnkill.ip-mobilphone.net> wrote in message
news:l.990669401.1582244873@adsl-151-197-234-248.phila.adsl.bellatlantic.net
 ...
> We have hundreds of scripts in directory dba
> and subdirectory.  In it, there is one line
> we need to change
> old: string= user\@mailserver1.com
> new: string= user\@mailserver2.down.net
>
> instead of change all those scripts one by one,
> I wrote a perl command line try to do this in one shot.
>
> perl -pi.bak -e "s/user\@mailserver1.com/user\
> @mailserver2.down.net" `find ./dba/ "*" -print`





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

Date: Thu, 24 May 2001 04:09:27 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Help:string match
Message-Id: <3B0C88AF.2E560501@acm.org>

u518615722@spawnkill.ip-mobilphone.net wrote:
> 
> We have hundreds of scripts in directory dba
> and subdirectory.  In it, there is one line
> we need to change
> old: string= user\@mailserver1.com
> new: string= user\@mailserver2.down.net
> 
> instead of change all those scripts one by one,
> I wrote a perl command line try to do this in one shot.
> 
> perl -pi.bak -e "s/user\@mailserver1.com/user\
> @mailserver2.down.net" `find ./dba/ "*" -print`
> 
> maybe because of the escape issue, this did not work,
> so I tried
> perl -pi.bak -e "s/user\\@mailserver1.com/user\\
> @mailserver2.down.net" `find ./dba/ "*" -print`
> 
> and
> perl -pi.bak -e "s/user\\\@mailserver1.com/user\\\
> @mailserver2.down.net" `find ./dba/ "*" -print`
> 
> none of them worked.
> 
> Is there any better way of doing it or I have to change the script
> one by one, look through all the files directory after directory?

perl -pi.bak -e 's/user\@mailserver1\.com/user\@mailserver2.down.net/'
`find /dba -print`


John
-- 
use Perl;
program
fulfillment


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

Date: Wed, 23 May 2001 21:47:24 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Is it possible to find the position of a mismatch using regular  expressions in Perl?
Message-Id: <3B0C682C.9972CDF3@earthlink.net>

Craig Manley wrote:
> 
> Hi all,
> 
> I've got this simple regular expression that checks the syntax of a
> string of comma seperated phonenumbers starting with 00. The problem
> is - if the string doesn't match my regex, then I don't know where the
> mismatch occured. Is there a practical solution to this problem?
> 
> my $req = '0031615015032,0031655388294,0031620075361';
> if ($req =~ /^00\d{7,14}(,00\d{7,14}){0,999}$/) {
>  print "Match\n";
> }
> else {
>  print "No match!\n";
>  # but at which character position did the matching go wrong?
> }

Why not split on the commas, and examine each number?
my $req = '0031615015032,0031655388294,0031620075361';
my ($pos, $match) = (0,1);
for( split /,/, $req ) {
	if( /^00\d{7,14}$/ ) {
		$pos += length($_) + 1;
	} else {
		print "Match failed for number starting at $pos\n";
		$match = 0;
		last;
	}
}
print "No match (no numbers!)\n" if !$req;
print "Match\n" if $match && $req;

By the way, I'm fairly sure that there are some places in the world with
6 digit numbers, and there may even be some places with 5 digit numbers.

-- 
Customer: "I would like to try on that suit in the window."
Salesman: "Sorry sir, you will have to use the dressing room."


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

Date: Wed, 23 May 2001 10:09:56 +0930
From: Chris <rebelvideo@hotmail.com>
Subject: Re: Module DB_File on NT
Message-Id: <3B0B06DC.744E1CF4@hotmail.com>

Hi

I have Active State on my NT machine and it runs DB_File no worries

you  may need to start ppm and install it to your machine

heres a screen dump of the first stage

C:\Perl\bin>ppm
PPM interactive shell (2.1.2) - type 'help' for available commands.
PPM> search db_file
Packages available from
http://ppm.ActiveState.com/cgibin/PPM/ppmserver.pl?urn:/PPMServer:
DB_File               [1.73]
DB_File-Lock          [0.04] Locking with flock wrapper for DB_File
Tie-DB_File-SplitHash [1.01] A wrapper around the DB_File Berkeley
database
PPM> install DB_File


after pressing enter it will upload and install the package

really bloody easy actually, they did a great job of it.


-- 
Regards

Chris
rebelvideo@hotmail.com


R wrote:
> 
> I've been working on a time sheet app, which thus far I have been developing
> on my linux station at work. thus far I have been using DB_File to handle my
> data.  lately I tried this on my nt station after adding active state and
> realized DB_File is not loaded even though it says it is.I tried downloading
> DB_File from CPAN but then realized it had to be compliled.  and I am
> clueless in C.  anyone have ideas


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

Date: Thu, 24 May 2001 12:51:58 +1000
From: "Merlin" <robert@quantum-radio.net.au>
Subject: need regex help please
Message-Id: <4E_O6.42$cQ4.11831@nsw.nnrp.telstra.net>


I have an expression here,
expires_on      => 'xpires\s+(.*?)\s*\n'
 that works fine, and returns the string correctly where the record
contains;
Expires on.......: May  22, 2001

Is it possible to modify this expression so that it finds _either_ 'xpires'
or 'xpiry' ??? or maybe even finds any string with just the 'xpir' in it?

Thanks for any help,
Robert






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

Date: Thu, 24 May 2001 05:06:10 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: need regex help please
Message-Id: <vm5pgtktdjh8l7pongln46uf3s43gc4tae@4ax.com>

Merlin wrote:

>I have an expression here,
>expires_on      => 'xpires\s+(.*?)\s*\n'
> that works fine, and returns the string correctly where the record
>contains;
>Expires on.......: May  22, 2001
>
>Is it possible to modify this expression so that it finds _either_ 'xpires'
>or 'xpiry' ??? or maybe even finds any string with just the 'xpir' in it?

	'xpir(?:es|y)\s+(.*?)\s*\n'
	'xpir\S*\s+(.*?)\s*\n'

-- 
	Bart.


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

Date: Thu, 24 May 2001 04:30:12 +0200
From: "Tim Lauterborn" <Tim.Lauterborn@gmx.de>
Subject: Recognize a number
Message-Id: <9ehrrj$hc$1@nets3.rz.RWTH-Aachen.DE>

Hi,

I am looking for a regular expression that recognizes numbers. If they have
a trailing + or - they should be accepted too.

For example:
accepted:
20
+20
-20
 ...

not accepted:
20a
b20
--20
 ...

Thanks!

Greetings,
Tim




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

Date: Thu, 24 May 2001 12:18:12 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Recognize a number
Message-Id: <rv_O6.26$xP2.1398@vic.nntp.telstra.net>

"Tim Lauterborn" <Tim.Lauterborn@gmx.de> wrote in message
news:9ehrrj$hc$1@nets3.rz.RWTH-Aachen.DE...
> Hi,
>
> I am looking for a regular expression that recognizes numbers. If they
have
> a trailing + or - they should be accepted too.

 leading + or - according to your sample data.

> For example:
> accepted:
> 20
> +20
> -20
> ...
>
> not accepted:
> 20a
> b20
> --20
> ...

This should do it.  Does not accept spaces or other characters.  Optional +
or - at the start of the string and at least one number.

/^[+-]?\d+$/

Wyzelli
--
#Modified from the original by Jim Menard
for(reverse(1..100)){$s=($_==1)? '':'s';print"$_ bottle$s of beer on the
wall,\n";
print"$_ bottle$s of beer,\nTake one down, pass it around,\n";
$_--;$s=($_==1)?'':'s';print"$_ bottle$s of beer on the
wall\n\n";}print'*burp*';




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

Date: Thu, 24 May 2001 07:23:44 +0200
From: Philip Newton <pne-news-20010524@newton.digitalspace.net>
Subject: Re: Recognize a number
Message-Id: <hl6pgt413u0mb456o5dj16uei32khbfm04@4ax.com>

On Thu, 24 May 2001 04:30:12 +0200, "Tim Lauterborn"
<Tim.Lauterborn@gmx.de> wrote:

> I am looking for a regular expression that recognizes numbers.

FAQ. Read `perldoc -q determine`. (This is one of the hits produced when
looking at `perldoc -q number`.)

> If they have a trailing + or - they should be accepted too.

Trailing sign?

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Thu, 24 May 2001 03:25:46 +0000 (UTC)
From: wjohnson@roger.ecn.purdue.edu (Wyatt R Johnson)
Subject: Re: sorting a scrolling_list()
Message-Id: <9ehuvq$plm$1@mozo.cc.purdue.edu>

In article <m3ititcejo.fsf@dhcp9-172.support.tivoli.com>,
Ren Maddox  <ren@tivoli.com> wrote:
>On Tue, 22 May 2001, wjohnson@roger.ecn.purdue.edu wrote:
>
>> 
>
>From "perldoc CGI":
>
>  print $query->scrolling_list(-name=>'list_name',
>                               -values=>['eenie','meenie','minie','moe'],
>                               -default=>['eenie','moe'],
>                               -size=>5,
>                               -multiple=>'true',
>                               -labels=>\%labels);
>
>So the answer is, pass an array ref for "-values" that is in the order
>you want, and pass the hash for "-labels".
>

I saw this example, but when I do it, the keys of my %labels (which
should be the internal values) do not get used. Instead, the values
get passed to the cgi script.

Wyatt
-- 
Mix ignorance with arrogance at low altitude and the results are almost 
guaranteed to be spectacular.
  -- Bruce Landsberg, Executive Director of the AOPA Air Safety Foundation.


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

Date: Wed, 23 May 2001 21:26:54 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: url parsing
Message-Id: <3B0C635E.B7040473@earthlink.net>

Craig Berry wrote:
> 
> Patrick Joyce (joycefive@earthlink.net) wrote:
> : I need a program that takes a url and strips out everything but the
> : domain this would normally not be as hard but i need this to work
> : for such urls as ".com.au, .co.jp" and "foo.me.com, hi.test.you.com"
> : so if my url was http://www.tiac/net/users/candvr then i would only
> : want tiac.net.
> 
> One way, assuming vanilla http urls:
> 
>   ($domain) = $url =~ m!//(.*?)/!;

But that doesn't work if the string is, eg, "http://www.tiac.net" with
no trailing slash.  Here is an untested regex which should work for all
valid urls.

	($proto, $domain, $path) = $url =~ m[
	(\w+)  :  (?://([^/\s]*))?  (\S*)  ]x;

This should work ok with any of:
	proto://host/path
	proto://host/
	proto://host
	proto:///path
	proto:path

The last two forms are common for file urls (file:///usr/local/... or
file:/usr/local/...) and the last is common for news urls
(news:comp.lang.perl.misc).  Path will include a leading slash, if one
is there.  Host does *not* include the leading // if it is there.

Now here's an OT question for you all:  If I have a file url with a host
(eg file://host/path), should I use ftp or my windows network
neighborhood?

-- 
Customer: "I would like to try on that suit in the window."
Salesman: "Sorry sir, you will have to use the dressing room."


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

Date: Thu, 24 May 2001 05:10:08 GMT
From: Scratchie <AgitatorsBand@yahoo.com>
Subject: Re: wwwboard.pl - Taint and Use Strict
Message-Id: <QI0P6.125$aG6.11013@news.shore.net>

Chris Stith <mischief@velma.motion.net> wrote:
: From the overall quality of Matt Wright's Perl work, I'd say you've
: either done some major gutting and reworking to make it secure, or
: you're overestimating the quality of your final product.

Probably both. Let me see if I can dig it up.

--Art


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

Date: Thu, 24 May 2001 05:30:25 GMT
From: Scratchie <AgitatorsBand@yahoo.com>
Subject: Re: wwwboard.pl - Taint and Use Strict
Message-Id: <R%0P6.126$aG6.11013@news.shore.net>

Alan J. Flavell <flavell@mail.cern.ch> wrote:
: On Wed, 23 May 2001, Scratchie wrote:

:> Not at all. I re-wrote Matt's wwwboard to run under -T and use strict in
:> less than a day.

: You're not a beginner at this game, though, are you?

True enough... I missed that the very first poster was a newbie and was
reacting to the comments of someone who was following him up. Still, I
wouldn't discourage any newbie who understands the security information in
the perl docs from giving it a whirl themselves. 

:> Fixed the bug that nailed the Alaskan Electrcian, too.

: But you give the impression that you could write this sort of thing
: from scratch too: so that's not a fair comparison with a naive newbie
: who's just discovered a hoard (or do I mean a dumpster?) of scripts
: written by someone called Matt.

True. I just wanted to emphasize that it's possible for someone of (at
most) middling perl ability to fashion a usable script out of one of
Matt's. Typically, any mention of Matt's scripts around here elicits a
response of "Gag, ack, barf... don't go near that with someone else's
computer... just write your own". In fact, based on this one script (the
only one of his I've looked at closely), Matt was fairly clever and simply
inexperienced. His basic idea for his wwwboard is, IMO, very smart: he
writes all the messages to static files and updates whatever other static
files need to point to them, so that when users are simply browsing the
messages (rather than updating them), it's just a set of static pages, no
CGI required. That basic idea is a sound programming practice, even if the
implementation left a lot to be desired. 

Anyway, I found my version and I'll try to post it in a couple of days so
you all can rip it apart (it needs some cleaning up and additional
comments). I wouldn't want to charge someone money for it, but for a free
CGI message board, I think it's a notch or two above the original. 

--Art


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

Date: Wed, 23 May 2001 23:20:57 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: wwwboard.pl - Taint and Use Strict
Message-Id: <3B0CA849.A2CC6957@stomp.stomp.tokyo>

Scratchie wrote:
 
> Alan J. Flavell wrote:
> > Scratchie wrote:

(various snippage)
 
> :> Not at all. I re-wrote Matt's wwwboard to run under -T and use strict in
> :> less than a day.
 
> : But you give the impression that you could write this sort of thing
> : from scratch too: so that's not a fair comparison with a naive newbie
> : who's just discovered a hoard (or do I mean a dumpster?) of scripts
> : written by someone called Matt.
 
> True. I just wanted to emphasize that it's possible for someone of (at
> most) middling perl ability to fashion a usable script out of one of
> Matt's. Typically, any mention of Matt's scripts around here elicits a
> response of "Gag, ack, barf...

I find good humor when this topic of Matt's scripts appears,
very ironic humor. Personally, I believe Matt is performing
a valuable service by providing his time and effort, for free.

This ironic humor is other than Randal and perhaps one or two
others whom have slipped out of my memory, I know of no others
here who actually write or have written any real programs.
Well, there is one other who has programmed a chatline but
can never speak of this because people will quickly realize
his name actually is Frank. Nonetheless, his chatlines, 
compared to mine, pale to a point of being Hello World! 
scripts. Tacky stuff and easy for a clever person like me
to hack, as he is aware, with significant embarrassment.

* hears a sound of an axe grinding *

Pretty funny stuff. I read a lot of you boys bragging about
this, bragging about that, although I have yet to witness
any of you actually writing a full featured program. Sure
doesn't stop you from ragging on Matt who actually does
write programs, decent ones considering they are free.

Ya know, just one feature of dozens in my chatline scripts
makes most of you braggarts appear to be, well, shall I say,
less than talented.

I have an idea. Why don't you walk the talk like I do?


Godzilla!


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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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

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

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


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


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