[16439] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3851 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jul 30 18:10:25 2000

Date: Sun, 30 Jul 2000 15:10:15 -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: <964995014-v9-i3851@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 30 Jul 2000     Volume: 9 Number: 3851

Today's topics:
    Re: Problems with next; in subroutines <noemail@nodomain.com>
        Quotes in regex? <kdfoust@fea.net>
    Re: Quotes in regex? <dietmar.staab@t-online.de>
    Re: Quotes in regex? <godzilla@stomp.stomp.tokyo>
    Re: Quotes in regex? (Colin Keith)
    Re: Quotes in regex? (Keith Calvert Ivey)
    Re: Removing all HTML tags from a String (Colin Keith)
    Re: Removing all HTML tags from a String <gellyfish@gellyfish.com>
    Re: Running other programs in background ericr@yankthechain.com
    Re: Running other programs in background <bart.lateur@skynet.be>
    Re: Should truncate length be 0? <bart.lateur@skynet.be>
    Re: small regex problem (Colin Keith)
    Re: Substitute string <btrieger@mediaone.net>
        Tutorial Error? <ando@sympatico.ca>
    Re: Tutorial Error? <tony_curtis32@yahoo.com>
    Re: unpacking a string of unknown length? <tony_curtis32@yahoo.com>
    Re: unpacking a string of unknown length? (Keith Calvert Ivey)
    Re: wierd regular expression <john@propellor.com>
    Re: wierd regular expression <tina@streetmail.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Sun, 30 Jul 2000 20:13:07 GMT
From: "Dave A." <noemail@nodomain.com>
Subject: Re: Problems with next; in subroutines
Message-Id: <n%%g5.11337$Mt.162246@nnrp1.ptd.net>


"Keith Calvert Ivey" <kcivey@cpcug.org> wrote in message news:3984fb9c.45780537@news.newsguy.com...
: "Dave A." <noemail@nodomain.com> wrote:
:
: >So, when the alarm $timeout is reached, it runs it's own
: >sub routine. next; should tell the program to move along
: >to the next port in the foreach command, since it is the inner-most
: >loop at our current position in the program.
:
: That makes sense.  Sorry about misunderstanding before.  But
: aren't you missing an "alarm 0;" after the socket connection
: line?  You don't want the alarm subroutine to be triggered
: unless you're in that loop; otherwise, who knows what loop
: you'll be nexting out of 5 seconds later when there isn't a
: timeout.

True, but I wanted to at least get this part working first.

: And shouldn't you be using eval {} and localizing $SIG{ALRM},
: as in perlipc?

again, this does not solve my initial problem of just getting to the
next port in @ports.  I have re-coded to include eval() and
localized $SIG(ALRM), but w/ the same problem as before.
next;  nor next LABEL;  will re-start the loop w/ the next element (port)
in (@ports) :(

Maybe I should forget about shortening the code, and use
raw socket calls instead. Like I said, it worked that way.

 David





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

Date: Sun, 30 Jul 2000 12:28:53 -0700
From: "Kevin Foust" <kdfoust@fea.net>
Subject: Quotes in regex?
Message-Id: <so904i6po0b126@corp.supernews.com>

Hi:

I'm kind of new to Perl, but have been able to figure out most things.  I am
stumped on this one.  I wish to remove the following expression from a
string:
<font face="Arial" size="2">
I've tried all kinds of patterns with no success.  I really expected
something like:
$string =~ s/<f.*?\".*?\".*?\".*?\">//ig;
to work but alas I am thwarted.  I've also tried all kinds of other methods
of matching to no avail.  I suspect that the quotes are screwing up the
match, however, I'm unable to find, in the 4 frigg'n O'Reilly Perl books
I've got, a way to work this out.

Any solutions?

Thanks and have fun,
Kevin






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

Date: Sun, 30 Jul 2000 21:51:24 -0500
From: "Dietmar Staab" <dietmar.staab@t-online.de>
Subject: Re: Quotes in regex?
Message-Id: <8m20ul$bus$11$1@news.t-online.com>

In article <so904i6po0b126@corp.supernews.com>, "Kevin Foust"
<kdfoust@fea.net> wrote:

> I'm kind of new to Perl, but have been able to figure out most things. 
> I am stumped on this one.  I wish to remove the following expression
> from a string:
> <font face="Arial" size="2">
> I've tried all kinds of patterns with no success.  I really expected
> something like:
> $string =~ s/<f.*?\".*?\".*?\".*?\">//ig;

Hi Kevin,  what is exactly your problem and what do you wanna do? Do you
wanna parse a HTML document and remove all HTML-tags? If removing
HTML-Tags is what you want to obtain, you can use a much simpler regexp like
s/<[^>]*>//g; If this is not what you wanna know, give an example, what
you have and what you got (and what you expected to get). Perhaps I can
give you a hint - or someone else.

Greetings, Dietmar


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

Date: Sun, 30 Jul 2000 13:14:48 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Quotes in regex?
Message-Id: <39848CB8.FF20F373@stomp.stomp.tokyo>

Kevin Foust wrote:

> I'm kind of new to Perl, but have been able to
> figure out most things.  I am stumped on this one.

Yo! Another Newbie! Welcome to Mt. Mule Manure!
You are Newbie number 4,719,230,002 this month!


>  I wish to remove the following expression from a
> string:

> <font face="Arial" size="2">

> I've tried all kinds of patterns with no success.
> I really expected something like:

> $string =~ s/<f.*?\".*?\".*?\".*?\">//ig;

(snipped)

Have you considered a simple straightforth approach
such as deleting precisely what you want?

A test script and printed results follow. I have
included a little extra, sorta. First regex will
delete precisely what you have asked. Second regex
will delete all html tags. I included this:

|<"|">

in my second regex, not so much because you need
this but rather to prevent 'What If' people around
here from suffering a sudden bout of flammable
flatulence, leading them to jump up and down,
tear at their hair while making fiery humorous
noises along with screaming, "WHAT IF! WHAT IF!"

You can safely remove |<"|"> if you know none
of your visitors are What If people or none
of your visitors will be pulling pranks.

You will notice I have used " gi " for my first
regex and " g " for my second regex. This is 
global for do it everywhere and ignore to catch
both uppercase and lowercase letters. This " gi "
or " g " could be deleted if you don't want
to do this globally or are not case sensitive.
I would suggest you leave " gi " in there for
my first regex to catch all instances and leave
" g " in my second regex for the same reason,
a reason hinted by you in your regex code.

Quotes have nothing to do with this. You are
simply trying to make this too complex. However,
others will sointly make this even more complex,
thus, this is Mt. Mule Manure.

Use a simple approach. You won't go wrong.


Godzilla!

-- 
Alturus 5, Gamma Sector, Perl Manglers:
http://la.znet.com/~callgirl/webchat/nph-chahta.cgi



TEST SCRIPT:
____________

#!/usr/local/bin/perl

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


## Delete Selected HTML Tags:

print "Delete Selected HTML Tags:\n\n";

$string = 'Delete this: <font face="Arial" size="2"> POOF! It is deleted now.';

print "  Input:\n    $string \n\n";

$string =~ s/<font face="Arial" size="2">//gi;

print "  Output:\n    $string";


## Delete All HTML Tags:

print "\n\n\nDelete All HTML Tags:\n\n";

$string = 'Delete this: <div align="left"></div> POOF! It is deleted now.';

print "  Input:\n    $string \n\n";

$string =~ s/<([^>]+)>|<"|">//g;

print "  Output:\n    $string";

exit;


PRINTED RESULTS:
________________

Delete Selected HTML Tags:

  Input:
    Delete this: <font face="Arial" size="2"> POOF! It is deleted now. 

  Output:
    Delete this:  POOF! It is deleted now.


Delete All HTML Tags:

  Input:
    Delete this: <div align="left"></div> POOF! It is deleted now. 

  Output:
    Delete this:  POOF! It is deleted now.


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

Date: Sun, 30 Jul 2000 20:41:35 GMT
From: ckeith@clara.net (Colin Keith)
Subject: Re: Quotes in regex?
Message-Id: <3q0h5.39$DT4.2034686@nnrp2.clara.net>

In article <39848CB8.FF20F373@stomp.stomp.tokyo>, "Godzilla!" <godzilla@stomp.stomp.tokyo> wrote:
>Have you considered a simple straightforth approach
>such as deleting precisely what you want?

I was going to suggest that too. But then curiousity overcame me and I ran 
the two approaches under Benchmark. I was mildly surprised to see that 

$x =~ s/<font\s+face="arial"\s+size=(2|"2")\s+>//ig;

Takes longer than

$x =~ s/<f.*?\".*?\".*?\".*?\">//ig;


(I took a longish string with more than one occurrance of the match to make 
the /g work, and of course it line wraps in this posting.)

### PROGRAM ###
#!/usr/bin/perl -w
use strict;
use Benchmark;
timethese(10000,  {
 1 => sub { my($x) = '<font face="Arial" size="2">sdkfslkdsflkdsflk <font 
face="Arial" size="2">sdfklsdlkfklf sksf<font face="Arial" size="2">sfflk';
                     $x =~ s/<font\s+face="arial"\s+size=(2|"2")\s+>//ig;
          },
 2 => sub { my($x) = '<font face="Arial" size="2">sdkfslkdsflkdsflk <font 
face="Arial" size="2">sdfklsdlkfklf sksf<font face="Arial" size="2">sfflk ';
                     $x =~ s/<f.*?\".*?\".*?\".*?\">//ig;
          }
});

my($x) = '<font face="Arial" size="2">sdkfslkdsflkdsflk <font face="Arial" 
size="2">sdfklsdlkfklf sksf<font face="Arial" size="2">sfflk ';

$x =~ s/<f.*?\".*?\".*?\".*?\">//ig;

print "\$x = $x\n";

## Results:
maia% perl ./x
Benchmark: timing 10000 iterations of 1, 2...
         1:  1 wallclock secs ( 0.48 usr +  0.00 sys =  0.48 CPU)
         2:  0 wallclock secs ( 0.42 usr + -0.01 sys =  0.41 CPU)
$x = sdkfslkdsflkdsflk sdfklsdlkfklf sksfsfflk 


So, anyone care to explain to me why pattern matching with wildcard 
characters is faster than matching a block of text? I assumed that wanting 
a definite character to be followed by another definite character would 
reduce the amount of work done because it either matches or doesn't match 
you don't need to backtrace as much, etc. but ... ?

Col.


---
Colin Keith
Systems Administrator
Network Operations Team
ClaraNET (UK) Ltd. NOC


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

Date: Sun, 30 Jul 2000 20:26:24 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: Quotes in regex?
Message-Id: <39868baf.4798350@news.newsguy.com>

"Kevin Foust" <kdfoust@fea.net> wrote:

>I wish to remove the following expression from a string:
><font face="Arial" size="2">
>I've tried all kinds of patterns with no success.  I really expected
>something like:
>$string =~ s/<f.*?\".*?\".*?\".*?\">//ig;
>to work but alas I am thwarted.

Why do you think it didn't work?  It works for me.  There's
probably something wrong in another part of your code.

Your results may surprise you if your string contains lines like
these:

   <form action="/cgi-bin/script.pl" method="GET">
   <p><font size="-1"><input name="name" size="30"></font>
   <img src="a.gif" alt="<fish>"><img src="b.gif" alt=">>">

Also, you'll be wanting to remove the corresponding </font> as
well.  For a quick-and-dirty way to do the job, if you know that
there's nothing too funny about your HTML files and that there
are no nested <FONT> tags, you could use

   $string =~ s{<font\s+face="Arial"\s+size="2">(.*?)</font>}
               {$1}gis;

There's nothing special about quotes in regular expressions, so
there's no need to backslash them.

-- 
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC


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

Date: Sun, 30 Jul 2000 19:52:40 GMT
From: ckeith@clara.net (Colin Keith)
Subject: Re: Removing all HTML tags from a String
Message-Id: <cI%g5.35$DT4.2030057@nnrp2.clara.net>

In article <8lvfd9$rhd$1@nnrp1.deja.com>, aaron@preation.com wrote:
>I am attempting to remove every HTML tag from a large string which is
>made up of all the lines of an HTML page. My goal is to create plain
>text which I can put into a sort of search engine page as a
>representation of the content of that page for a PERL site search
>engine.

Try the HTML-Parser (and similar) modules from CPAN
http://cpan.valueclick.
com/modules/by-category/15_World_Wide_Web_HTML_HTTP_CGI/HTML/

See also
man perlfaq9

=head2 How do I remove HTML from a string?

In case you get stuck deciding what colour it is. .. 
(for the HHGTTG fans:)


---
Colin Keith
Systems Administrator
Network Operations Team
ClaraNET (UK) Ltd. NOC


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

Date: 30 Jul 2000 14:09:56 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Removing all HTML tags from a String
Message-Id: <8m19f4$kfe$1@orpheus.gellyfish.com>

On Sat, 29 Jul 2000 20:39:05 GMT aaron@preation.com wrote:
> 
> 
> I am attempting to remove every HTML tag from a large string which is
> made up of all the lines of an HTML page. My goal is to create plain
> text which I can put into a sort of search engine page as a
> representation of the content of that page for a PERL site search
> engine.
> 

look at perlfaq9 :

       How do I remove HTML from a string?

perldoc -q HTML

And to answer your next question :

#!/usr/bin/perl -w

use HTML::Parser;

use strict;

my $parser = HTML::Parser->new(api_version => 3,
                               text_h => [ sub { print shift; },"dtext" ]);


$parser->parse_file(*STDIN);


You would substitute the parse() method if you had your HTML in a variable.

/J\
-- 
yapc::Europe in assocation with the Institute Of Contemporary Arts
   <http://www.yapc.org/Europe/>   <http://www.ica.org.uk>


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

Date: Sun, 30 Jul 2000 20:09:37 GMT
From: ericr@yankthechain.com
Subject: Re: Running other programs in background
Message-Id: <8m221v$h13$1@nnrp1.deja.com>

In article <r4r7os03fna4oboat1bdfs7v8e37obgmve@4ax.com>,
  Bart Lateur <bart.lateur@skynet.be> wrote:
> ericr@yankthechain.com wrote:
>
> >How can I make a Perl program run another program in the background?
> >When I try `programname` it freezes the perl program until the called
> >upon program has quit. Is there any way to do this?
>
> You're running Win32, as I gathered from another post.
>
> The simplest solution: do it through START:
>
> 	system('start', 'programname');
>
> which, however, may make a DOS window appear for a fraction of a
second.
>
> --
> 	Bart.

This worked perfectly, no dos window at all, thanks!

Now if only I could make the child program stay in the background of
the parent program or even be invisble (minimized would be fine) - I'm
writing a PTk program and I want to be able to play sound files in the
background while the program's going on... I know "system" can take
multiple arguments so I tried system
('start', 'programename', 'minimize'), but it thought minimize was part
of the programname path...

Any ideas?


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


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

Date: Sun, 30 Jul 2000 20:49:12 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Running other programs in background
Message-Id: <sh49osgtcajv2ntkfpdvrtmac634ouvc24@4ax.com>

ericr@yankthechain.com wrote:


>> 	system('start', 'programname');

>This worked perfectly, no dos window at all, thanks!
>
>Now if only I could make the child program stay in the background of
>the parent program or even be invisble (minimized would be fine)

I'd nnormally point you to the Win32::Process module, but that only
exists precompiled for ActiveState Perl 5.005. That is not binary
compatible with Perl 5.6.

I've looked through the WIN32API help file, and I found the WinExec API
call. You can call it through the Win32::API module. The specifications
are:

	file: kernel32
	parameters:	pointer to string = command line
			long = window style number
			SW_HIDE = 0
			SW_SHOWMINIMIZED = 2
			SW_MINIMIZE = 6
	return value:	long = error code if < 32

The docs say you ought to use CreateProcess instead, but this looks good
enough for me.

    use Win32::API;
    $WinExec = new Win32::API('kernel32','WinExec', [ 'P', 'N' ], 'N');
    my $return = $WinExec->Call('notepad', 0);

Gee, it works.

-- 
	Bart.


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

Date: Sun, 30 Jul 2000 20:31:11 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Should truncate length be 0?
Message-Id: <t349osgi79ugvaad5vs0td3gre9ao4lpm0@4ax.com>

M.J.T. Guy wrote:

>"perldoc perlport" says
>
>     truncate EXPR,LENGTH
>             Not implemented. (VMS)
>
>             Truncation to zero-length only. (VOS)

>So it looks like the only (known) problem is VOS.

"Not implemented" is not a problem?

-- 
	Bart.


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

Date: Sun, 30 Jul 2000 20:07:49 GMT
From: ckeith@clara.net (Colin Keith)
Subject: Re: small regex problem
Message-Id: <pW%g5.36$DT4.2031326@nnrp2.clara.net>

In article <8lulk9$aad$1@nnrp1.deja.com>, hamed53@my-deja.com wrote:
>I have this string:

How long is it? :)

>$string = "[10] OutBound Digits   : 111111        ";
>i want to extract: "10" and "OutBound Digits" and "111111" from it.
>
>I have written small regex myself, but it seems it only extracts a word
>"OutBound" and not the second word "Digits" where it should extract all
>words between "[10]" and ":"
>
>heres the code i've written
>
>$string =~ /^\[\s*(\d+)\] (\w*)\s+\: (.*)/;

Break it down. You ask for a match starting at the beginning of the scalar  
where the first character is a literal [ followed by 0 or more white space 
characters, followed by any digits 1+ times and closed by a literal ]

That matches.
A space followed by any number of word characters, followed by 1 or 
more white space characters. 

Again. That matches.
Then you want a : (we'll pretend you didn't backslash escape it because it 
doesn't need to be) That doesn't match.

The key here is the fact that you have a white space in the middle of your 
string. So the problem is that you have \w* matching, but then the next atom 
(is that the right word? I forget), the \s+ matches against the space 
between "OutBound" and "Digits". Because you've then specified that that 
space must be followed by a : ... it fails.

So we fix that with
([\w\s]+)

note the [ ] which indicate a grouping, so now anything that's a whitespace 
or word chacter will match, and the + means 1 or more times (this can go 
back to * if you might not have any entry)

Finished ... ? No. Because reg exps are greedy, so the \s will match as many 
white space characters as it can - the ones *after* the text that we want. 
So, you need to put a ? to make it 'non-greedy', thus:

([\w\s]+?)

Put it together and test...

maia% perl -w -Mstrict
my($string) = "[10] OutBound Digits   : 111111        ";
$string =~ /^\[\s*(\d+)\] ([\w\s]+?)\s+\: ([^\s]+)\s*$/;
print "\$1 = '$1'\n\$2 = '$2'\n\$3 = '$3'\n";

$1 = '10'
$2 = 'OutBound Digits'
$3 = '111111'

Note the trailing spaces are exclude from $3 by using [^\s] and the trailing 
\s* anchored to the end of the string slurps any trailing spaces (including 
any CR/LF characters).




>print "$1\n";
>print "$2\n";
>print "$3\n";
>
>Thanks for your help
>
>Hamed
>
>
>Sent via Deja.com http://www.deja.com/
>Before you buy.


---
Colin Keith
Systems Administrator
Network Operations Team
ClaraNET (UK) Ltd. NOC


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

Date: Sun, 30 Jul 2000 20:57:58 GMT
From: "btrieger" <btrieger@mediaone.net>
Subject: Re: Substitute string
Message-Id: <qF0h5.1510$_s1.34150@typhoon.ne.mediaone.net>


Sebastian Erlhofer <Seb.Erlhofer@evc.net> wrote in message
news:6ko2os8843ppvb24u50u6n654ebk3b53g9@4ax.com...
> Hi
>
> Can someone give me the code for this:
>
> Convert "../../mine.zip" -> "../mine.zip"
> It should also convert "../../../../../../../../../../mine.zip" to
> "../mine.zip"


s#(\.\./)+#../#;






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

Date: Sun, 30 Jul 2000 18:05:38 GMT
From: "Ando" <ando@sympatico.ca>
Subject: Tutorial Error?
Message-Id: <S7_g5.79054$1h3.1151170@news20.bellglobal.com>

Dear Perl NG users,

In the simple following script:

#!/usr/bin/perl
$classname = "CGI Programming 101";
print "Hello there.  What is your name?\n";
$you = <STDIN>;
chomp($you);
print "Hello, $you.  Welcome to $classname.\n";

the chomp in line 5 doesn't seem to want to work.  Do you see where the
error was made?

Removing Line 5 (  chomp($you);  ) makes it work, but does not remove the
\n.  You get output:

Hello, David
 .  Welcome to CGI Programming 101.

Any quick answer is fine.
Thanks,
David Anderson
(ando@sympatico.ca)




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

Date: 30 Jul 2000 13:12:16 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Tutorial Error?
Message-Id: <87r98bh4hr.fsf@limey.hpcc.uh.edu>

>> On Sun, 30 Jul 2000 18:05:38 GMT,
>> "Ando" <ando@sympatico.ca> said:

> Dear Perl NG users, In the simple following script:

> #!/usr/bin/perl $classname = "CGI Programming 101";
> print "Hello there.  What is your name?\n"; $you =
> <STDIN>; chomp($you); print "Hello, $you.  Welcome to
> $classname.\n";

> the chomp in line 5 doesn't seem to want to work.  Do
> you see where the error was made?

> Removing Line 5 ( chomp($you); ) makes it work, but does
> not remove the \n.  You get output:

> Hello, David .  Welcome to CGI Programming 101.

So what error do you get if you incorporate the chomp()?
You didn't tell us.  Actually the above code is correct.
chomp() will do what you want.

I think you are (a) using perl in a CGI context, (b) not
seeing the errors because they end up in a webserver's
error log somewhere, and (c) you're actually using (gasp)
perl4, which doesn't have chomp().

You should upgrade to the latest perl5 immediately (and
then don't forget -w and "use strict").

hth
t
-- 
"With $10,000, we'd be millionaires!"
                                           Homer Simpson


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

Date: 30 Jul 2000 13:07:15 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: unpacking a string of unknown length?
Message-Id: <87u2d7h4q4.fsf@limey.hpcc.uh.edu>

>> On Sun, 30 Jul 2000 17:27:29 GMT,
>> "Daniel Ditlew" <ditlew@abk.auc.dk> said:

> My doc on unpack seems very sparce..  I cant figure out
> how to unpack a string of unknown length followed by
> something else..  example: I cant unpacked the
> following: "unknown_name 40"

> I cant use: $unpacked = unpack("A* i", $packed);

You'd probably want @unpacked, since unpack() returns a
list of the values it unpacked.  "perldoc -f unpack" for
what this function does in list or scalar context.

> and since the length is unknown I cant use this either:
> $unpacked = unpack("A12 i", $packed);

[un]pack probably isn't the way to go about this.  Use
split() to get the bits, e.g.

    @components = split /\s+/, $string;

       ==> ('unknown_name', 40)

If you know what the separator is between the parts, and
it sounds like this is the case, you just split() on a
regexp which matches this.

hth
t
-- 
"With $10,000, we'd be millionaires!"
                                           Homer Simpson


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

Date: Sun, 30 Jul 2000 19:29:19 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: unpacking a string of unknown length?
Message-Id: <39858164.2162921@news.newsguy.com>

"Daniel Ditlew" <ditlew@abk.auc.dk> wrote:

>I cant unpacked the following:
>"unknown_name 40"
>
>I cant use:
>$unpacked = unpack("A* i", $packed);
>
>and since the length is unknown I cant use this either:
>$unpacked = unpack("A12 i", $packed);

How is Perl supposed to know where you want the string to end if
you don't tell it?  I think you may want a regex.

-- 
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC


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

Date: Sun, 30 Jul 2000 23:51:25 +0200
From: john <john@propellor.com>
Subject: Re: wierd regular expression
Message-Id: <3984A35D.35B4FF66@propellor.com>

I don't think so...
the code looks like this:

foreach my $line(@layout){
$line=~s/<TEXT>/$text/g;
$line=~s/<SUBJECT>/$subject/g;
$line=~s/<EMAIL>/$email/g;
print $line;
}

and it run several times for different values of $text,$subject and
$email





"Andrew N. McGuire" wrote:
> 
> On Sun, 30 Jul 2000, john quoth:
> 
> $$ I have done the most simple regular expression, replacing a certain text
> $$ with the content of a variable:
> $$
> $$ s/text/$variable/gi
> $$
> $$ the expression is used several times, with different values of
> $$ $variable:
> $$ for example "text" is first replaced with "pig", later with "chicken"
> $$ and finally with "hotdog".
> $$
> $$ but - after using this expression once, it keep replacing the given text
> $$ with the first value of $variable, ignoring the new values - so the
> $$ string "text" will always be replaced with "pig" even if later $variable
> $$ is "chicken" or "hotdog".
> $$ is there a way to prevent this strange behavior?
> 
> Well since you did not post any code, I will have assume.
> After the first substitution, you have replaced 'text' with 'pig'.
> Your string no longer contains 'text' so subsequent substitutions
> will fail, and the text will remain with the word pig.  If you
> want to avoid this make a copy of your data before modifying it,
> so that you can restore the copy when necessary.
> 
> anm
> --
> /*------------------------------------------------------------------------.
> | Andrew N. McGuire                                                       |
> | anmcguire@ce.mediaone.net                                               |
> | perl -le'print map?"(.*)"?&&($_=$1)&&s](\w+)]\u$1]g&&$_=>`perldoc -qj`' |
> `------------------------------------------------------------------------*/


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

Date: 30 Jul 2000 21:27:05 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: wierd regular expression
Message-Id: <8m26j9$5g216$10@ID-24002.news.cis.dfn.de>

hi,
john <john@propellor.com> wrote:
> I don't think so...
> the code looks like this:

> foreach my $line(@layout){
> $line=~s/<TEXT>/$text/g;
> $line=~s/<SUBJECT>/$subject/g;
> $line=~s/<EMAIL>/$email/g;
> print $line;
> }

> and it run several times for different values of $text,$subject and
> $email

well, as it was said before, once all the <TEXT>,<SUBJECT> etc
are replaced, $line does *not* contain them any more.
what do you mean with "run several times for
different values"? the above code works, of course.

you should know that the values in @layout
are all changed after the foreach loop. if
you don't want to change them, use
foreach (@layout) {
 my $line = $_;
 $line =~ s....
 ...
}

> [ fullquote deleted ]

tina

-- 
http://tinita.de    \  enter__| |__the___ _ _ ___
tina's moviedatabase \     / _` / _ \/ _ \ '_(_-< of
search & add comments \    \ _,_\ __/\ __/_| /__/ perception
"The Software required Win98 or better, so I installed Linux."


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

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


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