[21745] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3949 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 10 14:21:50 2002

Date: Thu, 10 Oct 2002 11:20:27 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 10 Oct 2002     Volume: 10 Number: 3949

Today's topics:
        regular expression question. <mario.lat@libero.it>
    Re: regular expression question. <pavel@gingerall.cz>
    Re: regular expression question. <dd@4pro.net>
    Re: regular expression question. (Tad McClellan)
    Re: regular expression question. <dd@4pro.net>
    Re: Run perl script on web server from command line <ignore@nobody.com>
    Re: Run perl script on web server from command line (Helgi Briem)
    Re: Run perl script on web server from command line (Tad McClellan)
        Search string in perl, take left characters (gina)
    Re: Search string in perl, take left characters (tî'pô)
    Re: Search string in perl, take left characters <pavel@gingerall.cz>
    Re: Search string in perl, take left characters <jurgenex@hotmail.com>
    Re: Search string in perl, take left characters (Dave Von Pless)
        Should -i eat my files? <johannes.fuernkranz@t-online.de>
    Re: String manipulation help needed (Rob)
    Re: String manipulation help needed (Tad McClellan)
        Strongger paragraph mode record separator <sun_tong_001@yahoo.com>
        Switch.pm not threadsafe? (Marc Shapiro)
        Synchronizing my perl processes (D. Alvarado)
    Re: Synchronizing my perl processes <kschroeder@coserv.net>
        The Perl Journal needs help (neanti)
    Re: tied hash consumes all memory <bkennedy@hmsonline.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 10 Oct 2002 14:41:55 GMT
From: _MarioLatens <mario.lat@libero.it>
Subject: regular expression question.
Message-Id: <pan.2002.10.10.14.21.00.24775.1595@libero.it>

I have in a variable $text a lot of text
for example: 
$text="line1
line2
line3
line...
line with word   tosearch1
line100
line..
line with word tosearch2
line 203
line..
";

how can I get in another variable $text2 
whith text between the line which contain words "tosearch1" and word
"tosearch2"

I mean how can i say :

$text2="
line with word   tosearch1
line100
line..
line with word tosearch2
";

Thank you in advance, Mario.

Sorry for dummy question... I'm a newbye!


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

Date: Thu, 10 Oct 2002 17:34:12 +0200
From: Pavel Hlavnicka <pavel@gingerall.cz>
Subject: Re: regular expression question.
Message-Id: <ao46iq$1re3$1@ns.felk.cvut.cz>

Suppose your string is in $foo.

$foo =~ /(^|\n)([^\n]+tosearch1.*?\n.*?tosearch2.*?)\n/s;

If you are sure tosearch[12] is at the very end of the line,

$foo =~ /(^|\n)([^\n]+tosearch1\n.*?tosearch2)\n/s;

is enough.

Pavel

_MarioLatens wrote:
> I have in a variable $text a lot of text
> for example: 
> $text="line1
> line2
> line3
> line...
> line with word   tosearch1
> line100
> line..
> line with word tosearch2
> line 203
> line..
> ";
> 
> how can I get in another variable $text2 
> whith text between the line which contain words "tosearch1" and word
> "tosearch2"
> 
> I mean how can i say :
> 
> $text2="
> line with word   tosearch1
> line100
> line..
> line with word tosearch2
> ";
> 
> Thank you in advance, Mario.
> 
> Sorry for dummy question... I'm a newbye!



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

Date: Thu, 10 Oct 2002 12:06:24 -0400
From: "Domizio Demichelis" <dd@4pro.net>
Subject: Re: regular expression question.
Message-Id: <ao48it$jb4i5$1@ID-159100.news.dfncis.de>

==== CODE ===
my $start;
my $text2;

while(<DATA>)
{
 $start++ if /tosearch1/;
 next unless $start;
 $text2 .= $_;
 last if /tosearch2/;
}

print $text2;

__DATA__
line1
line2
line3
line...
line with word   tosearch1
line100
line..
line with word tosearch2
line 203
line..
=== END CODE ===

nice to meet you here too :-)

--
-.. --- -- .. --.. .. ---
-.. . -- .. -.-. .... . .-.. .. ...




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

Date: Thu, 10 Oct 2002 11:40:15 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: regular expression question.
Message-Id: <slrnaqbbbf.3ff.tadmc@magna.augustmail.com>

_MarioLatens <mario.lat@libero.it> wrote:

> I have in a variable $text a lot of text

> how can I get in another variable $text2 
> whith text between the line which contain words "tosearch1" and word
> "tosearch2"


   my $text2 = $1 if $text =~ /(.*tosearch1(.*\n)*.*tosearch2\n)/;


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


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

Date: Thu, 10 Oct 2002 13:17:49 -0400
From: "Domizio Demichelis" <dd@4pro.net>
Subject: Re: regular expression question.
Message-Id: <ao4cqm$jb1e3$1@ID-159100.news.dfncis.de>

> between the line which contain words
 ... and if you are not sure if tosearch2 is the last word, you can change a
little the RE:

    my $text2 = $1 if $text =~ /(.*tosearch1(.*\n)*.*tosearch2.*\n)/;

--
-.. --- -- .. --.. .. ---
-.. . -- .. -.-. .... . .-.. .. ...


"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnaqbbbf.3ff.tadmc@magna.augustmail.com...
> _MarioLatens <mario.lat@libero.it> wrote:
>
> > I have in a variable $text a lot of text
>
> > how can I get in another variable $text2
> > whith text between the line which contain words "tosearch1" and word
> > "tosearch2"
>
>
>    my $text2 = $1 if $text =~ /(.*tosearch1(.*\n)*.*tosearch2\n)/;
>
>
> --
>     Tad McClellan                          SGML consulting
>     tadmc@augustmail.com                   Perl programming
>     Fort Worth, Texas






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

Date: Thu, 10 Oct 2002 10:50:51 -0400
From: "Chuck" <ignore@nobody.com>
Subject: Re: Run perl script on web server from command line
Message-Id: <ao444b$fbq$1@moonstone.imsb.nrc.ca>

> >> [snip upside-down quoted text. Please do not do that.]
>
> Which part exactly of Tad's:
>
> "snip upside-down quoted text. Please do not do that."
>
> did you not understand, Chuck?
>
> --
> Regards, Helgi Briem
> helgi AT decode DOT is
>

In the immortal words of Maxwell Smart, the part that came after "[".

Have a nice day, Helgi




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

Date: Thu, 10 Oct 2002 16:02:19 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Run perl script on web server from command line
Message-Id: <3da5a41b.133089182@news.cis.dfn.de>

On Thu, 10 Oct 2002 10:50:51 -0400, "Chuck"
<ignore@nobody.com> wrote:

>> >> [snip upside-down quoted text. Please do not do that.]
>>
>> Which part exactly of Tad's:
>> "snip upside-down quoted text. Please do not do that."
>> did you not understand, Chuck?

>In the immortal words of Maxwell Smart, the part that came after "[".
>Have a nice day, Helgi

I will and it was jsut made nicer by having a suggestion 
actually listened to and acted upon for a change.  

Thanks and good luck.  We'll be seeing you around again, 
I hope.
-- 
Regards, Helgi Briem
helgi AT decode DOT is

                           A: Top posting
                           Q: What is the most irritating thing on Usenet?
                                           - "Gordon" on apihna


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

Date: Thu, 10 Oct 2002 11:36:01 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Run perl script on web server from command line
Message-Id: <slrnaqbb3h.3ff.tadmc@magna.augustmail.com>

Chuck <ignore@nobody.com> wrote:
>> >> [snip upside-down quoted text. Please do not do that.]
>>
>> Which part exactly of Tad's:
>>
>> "snip upside-down quoted text. Please do not do that."
>>
>> did you not understand, Chuck?
>>
>> --
>> Regards, Helgi Briem
>> helgi AT decode DOT is



Now we can work of full-quoting.

Please do not quote .sigs


> In the immortal words of Maxwell Smart, the part that came after "[".


(wrapped)

   http://mail.augustmail.com/~tadmc/clpmisc/
     clpmisc_guidelines.html#item_Use_an_effective_followup_style


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


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

Date: 10 Oct 2002 07:51:27 -0700
From: glipuma@hotmail.com (gina)
Subject: Search string in perl, take left characters
Message-Id: <926fc4d4.0210100651.424878ba@posting.google.com>

I have only programmed in perl in college, so needless to say, I don't
know how to do it.  I have a string "64938  total" and I need to take
the number value from the string and convert that to an integer.  How
do I do this?  Thanks!


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

Date: Thu, 10 Oct 2002 17:17:12 +0200
From: "Teh (tî'pô)" <teh@mindless.com>
Subject: Re: Search string in perl, take left characters
Message-Id: <8d5bquot1s7duj4f5aet28comjio9pd6ti@4ax.com>

gina bravely attempted to attach 4 electrodes of knowledge to the
nipples of comp.lang.perl.misc by saying:
>I have only programmed in perl in college, so needless to say, I don't
>know how to do it.  I have a string "64938  total" and I need to take
>the number value from the string and convert that to an integer.  How
>do I do this?  Thanks!

Perl doesn't distinguish between strings and numbers too much.
Just grab the part that look like a number and you'll be fine.
Please not that I'm a newbie too so it may be safer wait a bit to see
if any flames follow ;o)

my $int = (split(/\s+/, $string))[0]; 

or
$string =~ /^(\d*)/;
my $int = $1;

or even, if you don't have warnings on (which is a Bad Thing)
my $int = 0 + $string;

Of course it all depends on how confident you are of the format that
string is in....


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

Date: Thu, 10 Oct 2002 17:22:21 +0200
From: Pavel Hlavnicka <pavel@gingerall.cz>
Subject: Re: Search string in perl, take left characters
Message-Id: <ao45sf$1r06$1@ns.felk.cvut.cz>

$foo = "64938  total";
$foo =~ /(\d+)/;;
print $1; # prints 64938

no conversion needed, just use it as an integer value.

gina wrote:
> I have only programmed in perl in college, so needless to say, I don't
> know how to do it.  I have a string "64938  total" and I need to take
> the number value from the string and convert that to an integer.  How
> do I do this?  Thanks!



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

Date: Thu, 10 Oct 2002 10:24:37 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Search string in perl, take left characters
Message-Id: <3da5b7d5$1@news.microsoft.com>

gina wrote:
> I have only programmed in perl in college, so needless to say, I don't
> know how to do it.  I have a string "64938  total" and I need to take
> the number value from the string and convert that to an integer.  How
> do I do this?  Thanks!

Just use it in numerical context, e.g.

    print "64638 total" + 10000000;

This will give you a warning when warnings are activated, but because you
know that in this case it's ok you can easily deactivate warnings for this
statement.

jue




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

Date: 10 Oct 2002 17:03:41 GMT
From: drdvpBLOCK@freeSPAMshell.org (Dave Von Pless)
Subject: Re: Search string in perl, take left characters
Message-Id: <ao4btd$6v59@kcweb01.netnews.att.com>

On 10 Oct 2002 07:51:27 -0700, gina <glipuma@hotmail.com> wrote:
> I have only programmed in perl in college, so needless to say, I don't
> know how to do it.  I have a string "64938  total" and I need to take
> the number value from the string and convert that to an integer.  How
> do I do this?  Thanks!

You posted the same question today in comp.lang.c and received some good advice.

You've received some good advice for how to do it in Perl here.

What's it going to be then, eh?


Dave
-- 
Dave Von Pless
Please remove the spam block to reply to me


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

Date: Thu, 10 Oct 2002 18:05:01 +0200
From: =?UTF-8?B?Sm9oYW5uZXMgRsO8cm5rcmFueg==?= <johannes.fuernkranz@t-online.de>
Subject: Should -i eat my files?
Message-Id: <ao48ir$34h$00$1@news.t-online.com>

$ perl -v

This is perl, v5.6.1 built for cygwin-multi

$ ls -l
total 4
-rw-r--r--    1 juffi    Kein            1 Oct 10 18:01 a
-rw-r--r--    1 juffi    Kein            1 Oct 10 18:01 b
-rw-r--r--    1 juffi    Kein            1 Oct 10 18:01 c
-rw-r--r--    1 juffi    Kein            1 Oct 10 18:01 d

$ perl -i -pe 's/x/y/g' *
Can't do inplace edit on a: Permission denied.
Can't do inplace edit on b: Permission denied.
Can't do inplace edit on c: Permission denied.
Can't do inplace edit on d: Permission denied.

$ ls -l
total 0

Is this normal?

(it works fine if I do -i.bak, but real men don't need backups, right? :-) )

						Juffi



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

Date: 10 Oct 2002 07:07:50 -0700
From: rob835@hotmail.com (Rob)
Subject: Re: String manipulation help needed
Message-Id: <6841b10c.0210100607.60cc64e8@posting.google.com>

tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnaq9i95.3sa.tadmc@magna.augustmail.com>...

>    my @A = map ord, split //, $test_string;

This works in practice, let me see if I understand this correctly.

my @A split //, $test_string; would return an array of characters
(including spaces) That was my big problem I didn't realize you could
use split with no arguments.

ord returns the number value for the first ascii character in the
string and map makes it process the entire string one character at a
time.  Did I miss anything?

Many thanks to all who responded,
Rob


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

Date: Thu, 10 Oct 2002 09:34:16 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: String manipulation help needed
Message-Id: <slrnaqb3v8.349.tadmc@magna.augustmail.com>

Rob <rob835@hotmail.com> wrote:
> tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnaq9i95.3sa.tadmc@magna.augustmail.com>...
> 
>>    my @A = map ord, split //, $test_string;
> 
> This works in practice, let me see if I understand this correctly.
> 
> my @A split //, $test_string; would return an array of characters
> (including spaces) 


Correct.


> That was my big problem I didn't realize you could
> use split with no arguments.


You _can_ call split() with no arguments, but my code called
split() with _two_ arguments.

If you mean that you did not know that split()ing on the
null pattern gets you each character, then you haven't
read the documentation for split().  :-)


> ord returns the number value for the first ascii character in the
> string and map makes it process the entire string one character at a
> time.  Did I miss anything?


That's about it.

A map is just a funny/compact way of writing a foreach loop.

Sometimes it helps to understand if you recast the map as a foreach:

   my @B;
   foreach my $char ( split //, $test_string ) {
      push @B, ord($char);
   }


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


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

Date: Thu, 10 Oct 2002 13:43:02 GMT
From: * Tong * <sun_tong_001@yahoo.com>
Subject: Strongger paragraph mode record separator
Message-Id: <3DA583E6.ACF678FA@yahoo.com>



* Tong * wrote:
> How can I read texts from a filehandle in paragraph mode?

Now, a tougher question, 

I want my script to be able to handle all those seem-to-be empty lines.
Trying to issue $/="\n\s*\n" won't help. 

Has anybody work on this before? Thanks

-- 
Tong (remove underscore(s) to reply)
  *niX Power Tools Project: http://xpt.sourceforge.net/
  - All free contribution & collection


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

Date: 10 Oct 2002 09:15:14 -0700
From: madas@comcast.net (Marc Shapiro)
Subject: Switch.pm not threadsafe?
Message-Id: <34108931.0210100815.7e202771@posting.google.com>

I just upgraded to Perl 5.8 so that I could use threads and switch
statements.  Unfortunately, they don't seem to be compatible with each
other.  This minimal program:

#!/usr/bin/perl
use threads;
use Switch;
threads->new(sub{})->join;

generates the error:

Scalars leaked: 1

Note that there isn't even a switch statement.  I take this to mean
that Switch.pm is not threadsafe.  I did look at the code in
Switch.pm, but it's way beyond me.

Any ideas?

Thanks,

Marc Shapiro
madas@comcast.net
http://www.baltolug.org/


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

Date: 10 Oct 2002 07:02:12 -0700
From: laredotornado@zipmail.com (D. Alvarado)
Subject: Synchronizing my perl processes
Message-Id: <9fe1f2ad.0210100602.27c04841@posting.google.com>

Hi, I have a perl script, call it, "mine.pl", which I'm running on our
Solaris servers.  Basically I don't want more than one instance
running at a time, and if the script is attempted to run through the
command

> perl mine.pl

while another instance of mine.pl is running, I'd like the second
instance to sleep until the first instance is finished running, and
then continue running (This is called a join, right?).

Does anyone have any suggestions on how to do this?  Maybe there
aren't appropriate mechanisms in Perl, but I'm not opposed to invoking
some Solaris processes through "`"s.

Thanks, Dave


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

Date: Thu, 10 Oct 2002 09:13:50 -0500
From: "Kevin Schroeder" <kschroeder@coserv.net>
Subject: Re: Synchronizing my perl processes
Message-Id: <uqb2vfnud3d0d1@corp.supernews.com>

Dave,
    One thing you could try doing is having a lock file that you use.  When
a new process is started it checks the lockfile to see if there is another
process running.  If so it sleeps for a second or two and then checks again.
If the file isn't there it creates a new lock file and does it's stuff.
Once done, it removes the lock file.  There may other ways to do it, but
this is the simplest way I can think of.

--
Kevin Schroeder
http://www.mirageworks.com
Member of www.sitedevelopersnetwork.com


"D. Alvarado" <laredotornado@zipmail.com> wrote in message
news:9fe1f2ad.0210100602.27c04841@posting.google.com...
> Hi, I have a perl script, call it, "mine.pl", which I'm running on our
> Solaris servers.  Basically I don't want more than one instance
> running at a time, and if the script is attempted to run through the
> command
>
> > perl mine.pl
>
> while another instance of mine.pl is running, I'd like the second
> instance to sleep until the first instance is finished running, and
> then continue running (This is called a join, right?).
>
> Does anyone have any suggestions on how to do this?  Maybe there
> aren't appropriate mechanisms in Perl, but I'm not opposed to invoking
> some Solaris processes through "`"s.
>
> Thanks, Dave




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

Date: Thu, 10 Oct 2002 16:40:38 GMT
From: jojje@coolmail.org (neanti)
Subject: The Perl Journal needs help
Message-Id: <a4ip9.8$Or2.182017@uab.ericsson.se>

Hello all Perl hackers,

You might be interested to know about the current predicament that the Perl Journal is in.

Please help saving a great publication!

This is from http://use.perl.org/article.pl?sid=02/10/08/1835219:
rochlin <http://www.nw-apts.com> writes "Looks like The Perl Journal might not make it up for air after all. 
This blurb is on their website. <http://www.tpj.com/> 'Time is running short and we need your help if The 
Perl Journal is to get another chance at being the real deal. As of a couple of minutes ago, we only have 
881 subscriptions and the deadline is fast approaching. Please subscribe now. It only costs 3 cents per 
day to get the best Perl coverage anywhere.'" They need 3,000 subscribers to move forward.

JAPH,
neanti



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

Date: Thu, 10 Oct 2002 10:23:14 -0400
From: "Ben Kennedy" <bkennedy@hmsonline.com>
Subject: Re: tied hash consumes all memory
Message-Id: <41qdnRbdGfvhEDigXTWcoA@News.GigaNews.Com>


"stanton" <stanton@lightlink.com> wrote in message
news:3DA4C73A.DA4429FC@lightlink.com...

> I'm processing millions of lines and eventually the
> Perl program runs out of RAM and just hangs.  I'm running
> Activestate Perl 5.6.1 build 633 on Win2k.
>
> If I had had to guess, I would have thought a hash tied
> to a disk file wouldn't consume all memory and then hang.
>
> ...
>
> use DB_File;
>
> ...
>
>    untie %db;
>    print "db is untied, hit <ENTER> to resume";
>    # right here, 1.5GB of RAM is still taken; none has been freed

I would recommend adding "use strict;" to the top of the script.  One thing
that could cause this behavior is that you are storing your data in a hash
that isn't really tied.  This is the kind of error "use strict" is designed
to prevent by disallowing storage in a variable you haven't explictly said
is ok for use.  Be sure to declare %db with "my" and try running the script
under strict, and let us know what happens.

--Ben Kennedy




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

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


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