[15524] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2934 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 3 14:10:37 2000

Date: Wed, 3 May 2000 11:10:23 -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: <957377422-v9-i2934@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 3 May 2000     Volume: 9 Number: 2934

Today's topics:
    Re: Keys of Hash (Randal L. Schwartz)
    Re: Keys of Hash <samay1NOsaSPAM@hotmail.com.invalid>
    Re: Keys of Hash (Randal L. Schwartz)
    Re: Keys of Hash nobull@mail.com
    Re: Keys of Hash <lr@hpl.hp.com>
    Re: Killing a query with DBI/DBD <jeff@vpservices.com>
        migrate modules to perl5.6.0 (Danny Aldham)
    Re: Parse a String <iltzu@sci.invalid>
    Re: Parse a String <rootbeer@redcat.com>
    Re: Parse a String <lr@hpl.hp.com>
        Passing a reference to the return value of a function ( ()
    Re: Passing a reference to the return value of a functi <sariq@texas.net>
        Perl shopping carts compared (Danny Aldham)
    Re: Perl shopping carts compared birgitt@my-deja.com
    Re: Perl with WebSite 1.1 <rootbeer@redcat.com>
    Re: Problems with Installing JPL (Java-Perl Lingos) on  michael.s.roth@saic.com
    Re: program that prints itself (M.J.T. Guy)
    Re: program that prints itself (M.J.T. Guy)
    Re: PS <jeffrey.l.susanj@boeing.com>
    Re: PS <lr@hpl.hp.com>
    Re: Reading and Writing to a file exhacker@my-deja.com
    Re: Reading and Writing to a file <lr@hpl.hp.com>
    Re: Reading and Writing to a file <godzilla@stomp.stomp.tokyo>
    Re: reg.expr. for correct parentheses? (Ilya Zakharevich)
        Regex for not matching a particular string <desaim@holly.ColoState.EDU>
    Re: Regex for not matching a particular string <tony_curtis32@yahoo.com>
    Re: Regex for not matching a particular string nobull@mail.com
    Re: Regex for not matching a particular string <desaim@holly.ColoState.EDU>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 03 May 2000 09:13:54 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Keys of Hash
Message-Id: <m1g0rz7gsd.fsf@halfdome.holdit.com>

>>>>> "Vincent" == Vincent Murphy <Vincent.Murphy@Baltimore.Com> writes:

Randal> "you now have $first and $second - enjoy!";
Vincent> ---------------^
Vincent> a print may help here. :-)

No, I mean what I wrote.  A string is a valid expression, which when
followed by a semicolon, is a valid statement, which is part of a
valid block.  As I did not know what the OP wanted with those pairs, I
could put no real code in the middle.  Legal syntax, useless runtime
behavior... just for comment.

-- 
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: Wed, 03 May 2000 09:39:12 -0700
From: Samay <samay1NOsaSPAM@hotmail.com.invalid>
Subject: Re: Keys of Hash
Message-Id: <0d6a472c.8483c87a@usw-ex0104-031.remarq.com>

>
>Samay> How I can get it??
>
>for my $first (sort keys %X) {
>  for my $second (sort keys %{$X{$first}}) {
>    "you now have $first and $second - enjoy!";
>  }
>}
>
>print "Just another Perl hacker,"

Thank you for the answer.
However your answer uses 2 for loops and a sort etc..
Which makes O(N*N) algorithm.

I actually want this in tirms of O(N).
Is it possible??

Samay..








* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!



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

Date: 03 May 2000 09:48:50 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Keys of Hash
Message-Id: <m1r9bj4m19.fsf@halfdome.holdit.com>

>>>>> "Samay" == Samay  <samay1NOsaSPAM@hotmail.com.invalid> writes:

>> 
Samay> How I can get it??
>> 
>> for my $first (sort keys %X) {
>> for my $second (sort keys %{$X{$first}}) {
>> "you now have $first and $second - enjoy!";
>> }
>> }
>> 
>> print "Just another Perl hacker,"

Samay> Thank you for the answer.
Samay> However your answer uses 2 for loops and a sort etc..
Samay> Which makes O(N*N) algorithm.

Not really.  You'll have built keys in the second hashes only for
those elements you have.  You don't build keys for elements you don't
have.  Try it, you'll see.  I'm not "searching" anything.

If you're concerned about the time of "sort", just remove it.  It'll
give you apparently randomly-ordered output though.

Samay> I actually want this in tirms of O(N).
Samay> Is it possible??

Not only possible, already done. :)

-- 
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: 03 May 2000 18:08:11 +0100
From: nobull@mail.com
Subject: Re: Keys of Hash
Message-Id: <u9g0rzblz8.fsf@wcl-l.bham.ac.uk>

Samay <samay1NOsaSPAM@hotmail.com.invalid> writes:

> Hi, I have
>  $X{a}{b} = 'c';
>  $X{a}{d} = 'e';
>  $X{p}{b} = 'd';
>  $X{p}{r} = 'x';
> 
> etc..
> 
> I want to get the keys for this Hash in pair
> In other words
> I need to have the pair
> a b
> a d
> p b
> p r

> How I can get it??

I'll assume you don't want to limit this to a depth of two.

$X{a}{b} = 'c';
$X{a}{d} = 'e';
$X{p}{b} = 'd';
$X{p}{r} = 'x';

sub keys_recusive (\%) {
  my ($hash) = @_;
  return [] unless ref $hash eq 'HASH';
  my @keys; 
  for my $key (sort keys %$hash) {
    push @keys, map { [ $key, @$_ ] } &keys_recusive($hash->{$key});
  }
  @keys;
}

print join "\n", map { "@$_" } keys_recusive(%X);

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


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

Date: Wed, 3 May 2000 10:21:47 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Keys of Hash
Message-Id: <MPG.137a0007d2d9e07698a9d5@nntp.hpl.hp.com>

In article <m1g0rz7gsd.fsf@halfdome.holdit.com> on 03 May 2000 09:13:54 
-0700, Randal L. Schwartz <merlyn@stonehenge.com> says...
> >>>>> "Vincent" == Vincent Murphy <Vincent.Murphy@Baltimore.Com> writes:
> 
> Randal> "you now have $first and $second - enjoy!";
> Vincent> ---------------^
> Vincent> a print may help here. :-)
> 
> No, I mean what I wrote.  A string is a valid expression, which when
> followed by a semicolon, is a valid statement, which is part of a
> valid block.  As I did not know what the OP wanted with those pairs, I
> could put no real code in the middle.  Legal syntax, useless runtime
> behavior... just for comment.

Clearly.  Vincent should have noted the absence of either a newline or a 
'local $\ = "\n";'.

And if compiled with '-w', the snippet would draw a warning.

    Useless use of a constant in void context at ...

'Useless use'.  Nice oxymoron!  :-)

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Wed, 03 May 2000 08:08:03 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Killing a query with DBI/DBD
Message-Id: <391040D3.11357A14@vpservices.com>

"Jeffrey P. Medeiros" wrote:
> 
> Is there an API call to kill a query with DBI/DBD? I would like to kill a
> query in the case of mistyped information or an unusually long query.
> 
> I'm using the Informix DBD.

If by mistyped you mean "incorrect SQL", then the query will die by
itself once DBI/DBD discovers it can't parse it.  If by mistyped you
mean "they were thinking the wrong thing", sorry the DWIM module is not
sophisticated enought to catch that yet :-).

For the long query, check to see if Informix and/or DBD::Informix
support a LIMIT clause, or, if they don't, just put a counter in your
fetch loop and break out of the loop after the counter gets too high.

-- 
Jeff


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

Date: 3 May 2000 17:08:41 GMT
From: danny@hendrix.postino.com (Danny Aldham)
Subject: migrate modules to perl5.6.0
Message-Id: <8epmep$css$1@hendrix.postino.com>

X-Newsreader: TIN [version 1.2 PL2]



I have just upgraded to perl5.6.0 . Maybe it was wishful thinking, but
I thought this version was going to allow me to upgrade perl without 
having to reinstall all my CPAN modules. How can I get a list of modules 
installed on my old perl suitable for feeding to the CPAN module to 
reinstall for me?

-- 
Danny Aldham     Providing Certified Internetworking Solutions to Business
www.postino.com  E-Mail, Web Servers, Mail Lists, Web Databases, SQL & Perl


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

Date: 3 May 2000 15:09:14 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Parse a String
Message-Id: <957366232.26940@itz.pp.sci.fi>

In article <39103268.E9480F5B@i-a.co.uk>, Andy Jeffries wrote:
>$x =~ s/\s(\S.*)/$1/;
>
>Should do the trick (is there not a trim function in Perl?).

It's pretty easy to write one:

  sub trim { for (@_ ? @_ : $_) { s/^\s+//; s/\s+$//; } }

Use it just like you'd use chomp().

-- 
Ilmari Karonen - http://www.sci.fi/~iltzu/
Please ignore Godzilla and its pseudonyms - do not feed the troll.



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

Date: Wed, 3 May 2000 09:05:35 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Parse a String
Message-Id: <Pine.GSO.4.10.10005030857080.13677-100000@user2.teleport.com>

On 3 May 2000, Ilmari Karonen wrote:

> >Should do the trick (is there not a trim function in Perl?).
> 
> It's pretty easy to write one:
> 
>   sub trim { for (@_ ? @_ : $_) { s/^\s+//; s/\s+$//; } }
> 
> Use it just like you'd use chomp().

It looks as if you're wanting this to work on $_ by default, but this
won't always work right. If you pass it an array which (by mistake or
design) may be empty, instead of processing that array, your code may
modify $_ unexpectedly. That's the kind of action-at-a-distance that can
be very difficult to debug. :-P

    my $file = 'may_be_empty';
    open FILE, $file
	or die "Can't open '$file': $!;
    trim(my @lines = <FILE>);
    close FILE;

It's not obvious which of those lines of code mangled $_ by mistake!

Alas, there's no way yet to safely write code which behaves just like many
built-ins. Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 3 May 2000 10:27:27 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Parse a String
Message-Id: <MPG.137a015bb210d5af98a9d6@nntp.hpl.hp.com>

In article <7abt2nr8n3.fsf@Merlin.i-did-not-set--mail-host-address--so-
shoot-me> on Wed, 03 May 2000 14:49:36 GMT, Ala Qumsieh 
<aqumsieh@hyperchip.com> says...

 ...

> Why the complications? Just remove the space(s):
> 
> 	$x =~ s/^\s*//;

Oh, no!  Spare us all the wasted CPU cycles when there is no leading 
whitespace.

> Of course, the FAQs have a lot to say about this. Check out perlfaq4.

Yes.  And it is done better in the FAQ.

  	$x =~ s/^\s+//;

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 3 May 2000 14:41:36 GMT
From: rlund@locutus.ucr.edu ()
Subject: Passing a reference to the return value of a function (list)
Message-Id: <8epdr0$3c8$1@pravda.ucr.edu>


sub make_list()
{
   return (1, 3);
}

sub add_lists($$)
{
   do_something;
}


now this works:

@l1 = make_list;
@l2 = make_list;
add_lists (\@l1, \@l2);

but this doesnt:

add_lists( \(make_list), \(make_list));


what's the proper syntax to make the above line work?

thanks!




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

Date: Wed, 03 May 2000 11:08:28 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: Passing a reference to the return value of a function (list)
Message-Id: <39104EFC.7FD68A3B@texas.net>

rlund@locutus.ucr.edu wrote:
> 
> sub make_list()
> {
>    return (1, 3);
> }
> 
> sub add_lists($$)
> {
>    do_something;
> }
> 
> now this works:
> 
> @l1 = make_list;
> @l2 = make_list;
> add_lists (\@l1, \@l2);
> 
> but this doesnt:
> 
> add_lists( \(make_list), \(make_list));
> 
> what's the proper syntax to make the above line work?

add_lists( [make_list], [make_list] );

- Tom


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

Date: 3 May 2000 05:08:52 GMT
From: danny@hendrix.postino.com (Danny Aldham)
Subject: Perl shopping carts compared
Message-Id: <8eoc94$nqd$1@hendrix.postino.com>

X-Newsreader: TIN [version 1.2 PL2]

I am evaluating two shopping carts, both Open Source, and both written in
perl. The two I am looking at are OpenMerchant at www.opensales.org and
Minivend at www.minivend.com . I was wondering if anyone has done this
already, (compared the two), and can give an assessment. Or, has anyone 
worked with either product that can give their opinion. 
I am concerned about security, extensability, and having input to the product
development. 

--
Danny Aldham     Providing Certified Internetworking Solutions to Business
www.postino.com  E-Mail, Web Servers, Mail Lists, Web Databases, SQL & Perl


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

Date: Wed, 03 May 2000 17:54:23 GMT
From: birgitt@my-deja.com
Subject: Re: Perl shopping carts compared
Message-Id: <8epp4b$ftm$1@nnrp1.deja.com>

In article <8eoc94$nqd$1@hendrix.postino.com>,
  danny@hendrix.postino.com (Danny Aldham) wrote:
> X-Newsreader: TIN [version 1.2 PL2]
>
> I am evaluating two shopping carts, both Open Source, and both written
> in perl. The two I am looking at are OpenMerchant at www.opensales.org
> and Minivend at www.minivend.com . I was wondering if anyone has done
> this already, (compared the two), and can give an assessment. Or, has
> anyone worked with either product that can give their opinion.
> I am concerned about security, extensability, and having input to the
> product development.
>

Why don't you post your question to the minivend-user and
minivend-consultant mailing list, read the evalutations and the
mail archives. That might give you some ideas and you might find
someone who knows and has used boths systems.


--
birgitt


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


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

Date: Wed, 3 May 2000 08:11:06 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Perl with WebSite 1.1
Message-Id: <Pine.GSO.4.10.10005030810240.13677-100000@user2.teleport.com>

On Wed, 3 May 2000, MC wrote:

> What do I need to do to WebSite 1.1 (yea yea i know its antique, but
> it works) to make it exectute perl scripts (in any directory)?

It sounds as if you want to search for the docs, FAQs, and newsgroups
about webservers in general and your webserver in particular. Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 03 May 2000 16:30:52 GMT
From: michael.s.roth@saic.com
Subject: Re: Problems with Installing JPL (Java-Perl Lingos) on Win NT
Message-Id: <8epk7t$aiv$1@nnrp1.deja.com>

John, I am having the same problem.  I have moved all of the .h files
that the source code references into the JNI directory and it seems to
be helping.  Now I am getting compiler errors inside the perl core
(ipersys.h).  Sorry I'm no help but I am commiserating with you.

Scott.

In article <8ek9fc$beu$1@nnrp1.deja.com>,
  johnpe@my-deja.com wrote:
> I have problems installing JPL (Java-Perl Lingos
> ) on the Windows NT system.
>
> *  I downloaded the source code of Perl 5.6.0.
> * My machine has JDK1.2.2.
> * I use Microsoft Visual C++ 6.0 as a compiler
> for the source code.
> * The compilation for perl 5.6.0 was successful.
> * Following the instruction, I cd to JPL
> directory and do the following:
>     perl Makefile.PL
>     nmake
>     nmake install
> It was successful.
>
> * Following the instruction, I cd to JNI
> directory to compile the closer.java class by
> using:
>        javac Closer.java
> It was successful.
>
> * Following the instruction, I
>         copy typemap.win32 typemap and then type:
>
>         perl Makefile.PL
>         nmake
>
> The CMD window gave a bunch of error messages
> such as:
> Jni.c
> JNI.xs(124):  error C2223: left of -
> >NewBooleanArray must point to struct/union.
> left of ->SetBooleanArrayRegion must point to
> struct/union
>
> I would appreciate if someone shares experience
> with installing JPL (Java-Perl Lovers) in Win32
> with JDK1.2.2.
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>


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


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

Date: 3 May 2000 16:07:13 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: program that prints itself
Message-Id: <8epirh$pp$1@pegasus.csx.cam.ac.uk>

John Lin <johnlin@chttl.com.tw> wrote:
>Philip 'Yes, that's my address' Newton wrote
>
>> My favorite prints itself to STDERR, not STDOUT:
>> Create a file called /tmp/quine.pl, containing the following line:
>>
>> Illegal division by zero at /tmp/quine.pl line 1.
>>
>> When run, it will produce itself as output.
>
>What astonished me was that
>"This is a legal Perl program!!!".
>(I noticed that the message is a run-time error.)

Only relatively legal.   Try running that with -w.

>perl -c /tmp/quine.pl
>
>/tmp/quine.pl syntax OK
>
>How come?

Try it with -w and Deparse  (best done with perl5.6.0):

% perl5.6.0 -wMO=Deparse /tmp/quine.pl
Unquoted string "at" may clash with future reserved word at /tmp/quine.pl line 1.
Unquoted string "tmp" may clash with future reserved word at /tmp/quine.pl line 1.
Unquoted string "quine" may clash with future reserved word at /tmp/quine.pl line 1.
'division'->Illegal('zero'->by('at' / 'tmp' / 'quine' . 'line'->pl(1)));
/tmp/quine.pl syntax OK


Mike Guy


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

Date: 3 May 2000 16:13:56 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: program that prints itself
Message-Id: <8epj84$19m$1@pegasus.csx.cam.ac.uk>

[ Drifting off-topic, but what the hell ... ]

Philip 'Yes, that's my address' Newton <nospam.newton@gmx.li> wrote:
>
>My favourite prints itself to STDERR, not STDOUT:
>
>Create a file called /tmp/quine.pl, containing the following line:
>
>Illegal division by zero at /tmp/quine.pl line 1.
>
>When run, it will produce itself as output. (This even works under
>Windows; put the file into \tmp\quine.pl but call it as 'perl
>/tmp/quine.pl'.)

That reminds me of a programming contest in Cambridge, back in the
dim and distant days when computers had valves in them:

    Produce the shortest piece of paper tape, which when fed into
    the EDSAC II will punch out a copy of itself *reversed*.

This was won by Peter Swinnerton-Dyer with an iterative solution:

    Take a random piece of paper tape from a rubbish bin.
    Feed it into the computer.
    Take the output, reverse it and feed it into the computer.
    Take the output, reverse it and feed it into the computer.
    Take the output, reverse it and feed it into the computer.
    Take the output, reverse it and feed it into the computer.
    Take the output, reverse it and feed it into the computer.
         ...

In practice this converged after about two iterations.


Mike Guy


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

Date: Wed, 3 May 2000 15:36:16 GMT
From: "Jeff Susanj" <jeffrey.l.susanj@boeing.com>
Subject: Re: PS
Message-Id: <Ftzq0I.LHy@news.boeing.com>

I am just learning Perl but my understanding from "Learning Perl on Win32"
is that the Win32 version ignores that line as just another comment.  It is
only file associations that determine how to execute a file.


Jeff S.


Dan Burch wrote in message <390F67F4.F6733A2E@teleport.com>...
>
>
>Dan Burch wrote:
>
>> David Featley wrote:
>>
>> > I am trying to run perl scripts via an apache web server on my local PC
>> > running windows 98 for local testing. I appear to be unable to get the
>> > script to output to my browser. All output is coming out in a dos text
>> > window.
>> >
>> > The simple script I am executing is:
>> >
>> > #!c:\perl\bin\perl.exe
>>
>
>> #!c:\perl\bin\perl  no .exe needed
>> Also if you put "SET PATH=C:\Perl\bin\perl"  in your autoexec.bat file
and
>> then restart you can just use #!perl
>>
>
>You must  have a blank line after the #! line.
>
>
>> >
>> > print "Content-type:text/html", "\n\n";
>> > print "hello world";
>> >
>> > I have active perl installed but have been reading that to run under
>> > win32 I need to recompile from the source, I have also seen from
various
>> > other posts that people are successfully running on Windows using
>> > "mod_perl", is this what the recompiled perl is referred to as? is this
>> > "recompiled" source available for download anywhere?
>> >
>> > Any help would be greatly appreciated.
>> >
>> > Thanks
>> >
>> > David
>




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

Date: Wed, 3 May 2000 10:02:16 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: PS
Message-Id: <MPG.1379fb71c3bd74ec98a9d3@nntp.hpl.hp.com>

[Rearranged and trimmed for readability.  Please respond to what you are 
quoting *after* you quote it, as I do here.]

In article <Ftzq0I.LHy@news.boeing.com> on Wed, 3 May 2000 15:36:16 GMT, 
Jeff Susanj <jeffrey.l.susanj@boeing.com> says...
> >> David Featley wrote:
> >>
> >> > I am trying to run perl scripts via an apache web server on my local PC
> >> > running windows 98 for local testing. I appear to be unable to get the
> >> > script to output to my browser. All output is coming out in a dos text
> >> > window.
> >> >
> >> > The simple script I am executing is:
> >> >
> >> > #!c:\perl\bin\perl.exe
> 
> I am just learning Perl but my understanding from "Learning Perl on Win32"
> is that the Win32 version ignores that line as just another comment.  It is
> only file associations that determine how to execute a file.

This is not the case for the Apache web server, which was specified in 
the otiginal post.  An absolute path to the perl executable must be 
specified.  Either orientation of slashes is acceptable.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Wed, 03 May 2000 16:00:17 GMT
From: exhacker@my-deja.com
Subject: Re: Reading and Writing to a file
Message-Id: <8epie5$8e7$1@nnrp1.deja.com>

In article <Pine.A41.4.10.10005031032360.18964-
100000@ginger.libs.uga.edu>,
  Brad Baxter <bmb@ginger.libs.uga.edu> wrote:
> On Wed, 26 Apr 2000, Carter Hamilton wrote:
>
> > I would like to open a text file and append something to the end of
certain
> > lines.  Is there any way to do this without copying the information
to a new
> > file?  I would like to do something like this:
> >
> > while (<TEXT>) {
> >     if (/$pattern/) {
> >         print TEXT chomp($_) . $newStuff . "\n";
> >     }
> >     else {
> >         print TEXT $_;
> >     }
> > }
>
> perldoc -q "how do i change one line in a file"
>
> See also:
>
>   perldoc perlfaq
>   perldoc perldoc
>
> --
> Brad
>
>

You would use the -i switch to Perl, which specifies that files
processed with the <> construct be edited in-place.


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


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

Date: Wed, 3 May 2000 09:41:45 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Reading and Writing to a file
Message-Id: <MPG.1379f6a2e20ef3c098a9d2@nntp.hpl.hp.com>

In article <Pine.A41.4.10.10005031032360.18964-
100000@ginger.libs.uga.edu> on Wed, 3 May 2000 10:33:51 -0400, Brad 
Baxter <bmb@ginger.libs.uga.edu> says...
> On Wed, 26 Apr 2000, Carter Hamilton wrote:
> 
> > I would like to open a text file and append something to the end of certain
> > lines.  Is there any way to do this without copying the information to a new
> > file?  I would like to do something like this:
> > 
> > while (<TEXT>) {
> >     if (/$pattern/) {
> >         print TEXT chomp($_) . $newStuff . "\n";

In addition, this code doesn't do what its author thinks it does.

perldoc -f chomp

> >     }
> >     else {
> >         print TEXT $_;
> >     }
> > }
> 
> perldoc -q "how do i change one line in a file"
> 
> See also:
> 
>   perldoc perlfaq
>   perldoc perldoc

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Wed, 03 May 2000 10:42:13 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Reading and Writing to a file
Message-Id: <391064F5.65224160@stomp.stomp.tokyo>

> On Wed, 26 Apr 2000, Carter Hamilton asks for help:
 
> I would like to open a text file and append something 
> to the end of certain lines.  Is there any way to do
> this without copying the information to a new
> file?  I would like to do something like this:

> while (<TEXT>) {
>     if (/$pattern/) {
>         print TEXT chomp($_) . $newStuff . "\n";


Open your data base for both read and write.
Test each line for your conditional.
If conditional is true, chomp and append newstuff.
Print to your data base.

Here is a simple test script you may 
modify and adapt if you wish. It can 
be run from the internet if needed by
uploading my script and by uploading a
test.txt with contents as shown with
read and write permissions on.

Contents of test.txt are first,
my test script next, then results.

Godzilla!

============


CONTENTS OF TEST.TXT :

false statement
true statement 
false statement
true statement



TEST SCRIPT:

#!/usr/local/bin/perl

print "Content-Type: text/plain\n\n";

$newstuff = "append this";

open (TEST, "+<test.txt");

@Test = <TEST>;

foreach $test_line (@Test)
 {
  if ($test_line =~ /true statement/)
   {
    chomp ($test_line);
    $test_line = join (" ", $test_line, $newstuff, "\n");
   }
  print TEST $test_line;
  print $test_line;
 }

close (TEST);

exit;


PRINTED RESULTS:

false statement
true statement append this 
false statement
true statement append this



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

Date: 3 May 2000 16:20:09 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: reg.expr. for correct parentheses?
Message-Id: <8epjjp$rni$1@charm.magnus.acs.ohio-state.edu>

[A complimentary Cc of this posting was sent to Tad McClellan
<tadmc@metronet.com>],
who wrote in article <slrn8h094h.7bi.tadmc@magna.metronet.com>:
> >I'm trying to get a list of all correctly parenthesized expressions from
> >a string.

>    Perl FAQ, part 6:
> 
>       "Can I use Perl regular expressions to match balanced text?"

And keep in mind that this entry of the FAQ is approximately of same
validity as a lot of the others: close to zilch.

Ilya


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

Date: Wed, 3 May 2000 10:07:50 -0600
From: Mitesh Desai <desaim@holly.ColoState.EDU>
Subject: Regex for not matching a particular string
Message-Id: <Pine.A41.4.10.10005031003060.214170-100000@holly.ColoState.EDU>

Is there a way of specifying a regular expression
in perl for matching a line if it that does not 
contain a particular string?

My problem is to find if the line contains 'abc',
but the 'abc' is not followed by 'def'. This is
not the exact problem, but the gist of it.

Thanks
Mitesh



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

Date: 03 May 2000 11:27:03 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Regex for not matching a particular string
Message-Id: <87u2gftx9k.fsf@shleppie.uh.edu>

>> On Wed, 3 May 2000 10:07:50 -0600,
>> Mitesh Desai <desaim@holly.ColoState.EDU> said:


> Is there a way of specifying a regular expression in
> perl for matching a line if it that does not contain a
> particular string?

> My problem is to find if the line contains 'abc', but
> the 'abc' is not followed by 'def'. This is not the
> exact problem, but the gist of it.

Woildn't it be simplest to perform the pattern match on
'abcdef' and just negate the if/else logic?

  if (/abcdef/) {
    print "abc followed by def, ignore it...\n";
  } else {
    do_whatever_to_abc_not_followed_by_def();
  }

That may not be exactly what you want but if you aren't
going to say what the real problem is, you can't expect
any more.

hth
t


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

Date: 03 May 2000 17:51:05 +0100
From: nobull@mail.com
Subject: Re: Regex for not matching a particular string
Message-Id: <u9k8hbbmrq.fsf@wcl-l.bham.ac.uk>

Mitesh Desai <desaim@holly.ColoState.EDU> writes:

> Is there a way of specifying a regular expression
> in perl for matching a line if it that does not 
> contain a particular string?

Yes see, perldoc perlre.

/^(?!.*a particular string)/

Of course it is way more effiecient to do it:

! /a particular string/

> My problem is to find if the line contains 'abc',
> but the 'abc' is not followed by 'def'.

Not followed immediately...

/abc(?!def)/

Or not followed at all...

/abc(?!.*def)/

> This is not the exact problem, but the gist of it.

As I said when almost this exact same question was asked by
0wn3d@my-deja.com a couple of weeks back it may be more efficient to
use:

/abc/ && $' !~ /def/ 

Now if 0wn3d@my-deja.com had shown the same consideration in choosing
a subject line that Mitesh showed then Mitesh would presumbaly have
been able to find the answer with a search engine.

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


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

Date: Wed, 3 May 2000 11:04:00 -0600
From: Mitesh Desai <desaim@holly.ColoState.EDU>
Subject: Re: Regex for not matching a particular string
Message-Id: <Pine.A41.4.10.10005031059500.107652-100000@holly.ColoState.EDU>

Okay, my problem is to check if the url contains http://,
and if it contains, check if it contains a particular
host, say www.cnn.com. Let us say it contains 
www.yahoo.com as the host, then my problem is to
insert a www.mysite.com/redirect? before it, to get

http://www.mysite.com/redirect?www.yahoo.com

I donot think the if not match would work, since it 
would even replace ftp://www.somesite.com.

Mitesh

On 3 May 2000, Tony Curtis wrote:

> >> On Wed, 3 May 2000 10:07:50 -0600,
> >> Mitesh Desai <desaim@holly.ColoState.EDU> said:
> 
> 
> > Is there a way of specifying a regular expression in
> > perl for matching a line if it that does not contain a
> > particular string?
> 
> > My problem is to find if the line contains 'abc', but
> > the 'abc' is not followed by 'def'. This is not the
> > exact problem, but the gist of it.
> 
> Woildn't it be simplest to perform the pattern match on
> 'abcdef' and just negate the if/else logic?
> 
>   if (/abcdef/) {
>     print "abc followed by def, ignore it...\n";
>   } else {
>     do_whatever_to_abc_not_followed_by_def();
>   }
> 
> That may not be exactly what you want but if you aren't
> going to say what the real problem is, you can't expect
> any more.
> 
> hth
> t
> 
> 



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

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


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