[23314] in Perl-Users-Digest
Perl-Users Digest, Issue: 5534 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Sep 21 00:05:56 2003
Date: Sat, 20 Sep 2003 21:05:08 -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 Sat, 20 Sep 2003 Volume: 10 Number: 5534
Today's topics:
Re: @_ in subroutine corrupts data? <bdonlan@users.sf.net>
Re: A (probable) error in perltoot ( perl5/5.8.0/pod/p (Himanshu Garg)
Re: convert .eml to .mbox in win32 <no-email-please@defunked.net>
Re: debugging <REMOVEsdnCAPS@comcast.net>
Difficulty removing element from array <ducott_99@yahoo.com>
Re: Difficulty removing element from array <cs@edu.edu>
Re: Little survey for Unix users (trwww)
Re: perl lib all over the place <samj2@austarmetro.com.au>
Re: Perl regular expression does not work on 5.8.0 <st.rupp@t-online.de>
program not being run <samj@austarmetro.com.au>
Re: program not being run <samj2@austarmetro.com.au>
Re: referencing, closures, classes (trwww)
Re: search a string <dave.nospam@ntlworld.com>
Re: search a string <jurgenex@hotmail.com>
Re: search a string <spam@thecouch.homeip.net>
Re: search a string (Tad McClellan)
Sending html mail with inline images <mcbass@lightsphere.de>
Re: simple server (Si Ballenger)
SOS! how to search & replace some string to numbers in <mizhael@yahoo.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 20 Sep 2003 17:54:01 -0400
From: bd <bdonlan@users.sf.net>
Subject: Re: @_ in subroutine corrupts data?
Message-Id: <psuu31-q36.ln1@bd-home-comp.no-ip.org>
synthespian wrote:
> hello --
>
> I can find no reasonable explanation for this behavior. Not theat
> there's isn't one (a trivial one at that), but I am having a hard time
> finding the reason for this:
>
> #!/usr/bin/perl
>
> @array = subthis(1, 2, 3, 4);
>
> sub subthis {
>
> @array = @_;
>
> foreach (@array) {
This is the same as foreach(1,2,3,4) {
> print "$array[$_]\n";
So this line prints $array[1], $array[2], etc. Since array numbering starts
at 0, it prints the last 3 elements, plus a nonexistent one. Perhaps you
meant:
foreach(@array){
print "$_\n";
}
Or:
for(my $i = 0; $i <= $#array; $i++){
print "$array[$_]\n";
}
[snip]
--
All generalizations are false, including this one.
-- Mark Twain
------------------------------
Date: 20 Sep 2003 20:28:54 -0700
From: himanshu@gdit.iiit.net (Himanshu Garg)
Subject: Re: A (probable) error in perltoot ( perl5/5.8.0/pod/perltoot.pod, line number 756 )
Message-Id: <a46e54c7.0309201928.1b98f60d@posting.google.com>
Dear Anno,
Thanks for the prompt reply. I have submitted the patch to bugs.perl.org.
Thank You
Himanshu.
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<bkfj4u$9sq$2@mamenchi.zrz.TU-Berlin.DE>...
> Himanshu Garg <himanshu@gdit.iiit.net> wrote in comp.lang.perl.misc:
> > Dear Perl Programmers,
> >
> > I tried out the code given in :-
> >
> > http://www.perldoc.com/perl5.8.0/pod/perltoot.html#Aggregation
> >
> > The following line :-
> >
> > printf "%s is really %s.\n", $him->name, $him->fullname;
> >
> > gives the following output :-
> >
> > Tommy is really Fullname=HASH(0x804c9b8).
> >
> > This happens because fullname returns an object reference as follows :-
> >
> > sub fullname
> > {
> > my $self = shift;
> > return $self->{FULLNAME};
> > }
> >
> > Therefore the line should probably be :-
> >
> > printf "%s is really %s.\n", $him->name, $him->fullname->as_string;
> >
> > Please correct me if I am wrong.
>
> Looks like you're right. Not a biggie, but you could send in a patch.
>
> Anno
------------------------------
Date: Sat, 20 Sep 2003 10:04:38 -0500
From: "J. Smith" <no-email-please@defunked.net>
Subject: Re: convert .eml to .mbox in win32
Message-Id: <vmor4uh1or30c6@corp.supernews.com>
use File::Find; # CPAN
This recurses directories.
**Be caureful, if you use this, as to what directory you are in when you
write to a file.** Remembered newbie mistake for me!
And call your code to as as sub routine.
"Mike James" <bill@my.place> wrote in message
news:Xns93FC9ABEF5E9maentigejmsethnnt@206.127.4.25...
> Hi, I'm working with some code I copied from here:
> http://www.usethesource.com/articles/02/06/17/1957223.shtml
>
> My system: WinXP Home, ActiveState Perl 5.6.1, operated by Perl newbie...
>
> The script is supposed to descend into sub-folders, read *.eml messages,
> then concatenate them into .mbox files. The problem is that the script
> doesn't descend into the sub-folders. Instead, it only operates on the
> files (and folders) in the folder where the script is located.
>
> Here's the script for convert.pl:
>
> sub convert
> {
> my ($file) = @_;
> my $from = '';
> my $date = '';
> my $message = '';
> my $stop_looking = 0;
>
> open OE, "<$file";
>
> while ()
> {
> my $line;
> chomp;
> $line = $_;
>
> $message .= $_ . "\n";
>
> if ( $stop_looking == 0 )
> {
> if ( $line =~ /(From:.*\<(.*)\>)/ )
> {
> $from = $2;
> }
> else
> {
> if ( $line =~ /(From: ([^\<]*))/ )
> {
> $from = $2;
> }
> }
>
> if ( $line =~ /Date: (.*)/ )
> {
> $date = $1;
>
> if ( $date =~ /(\w{3}), (\d+) (\w{3}) (\d{4}) (\d\d:
> \d\d:\d\d)/ )
> {
> my ($dow, $day, $month, $year, $time) = ($1,
> $2,$3,$4,$5);
>
> if ( $day =~ /0(\d)/ )
> {
> $day = " $1";
> }
>
> $date = "$dow $month $day $time $year";
> }
> }
>
> if ( $line =~ /X-UIDL:/ )
> {
> $message = "\n\nFrom $from $date\n" . $message;
>
> $stop_looking = 1;
> }
> }
> }
>
> close OE;
>
> return $message;
> }
>
> sub convert_folder
> {
> my ($folder) = @_;
> my @files = glob "$folder/*.eml";
>
> open MBOX, ">$folder.mbox";
> foreach my $file (@files)
> {
> print "File $file...\n";
> print MBOX convert( $file );
> }
> close MBOX;
> }
>
> my @folders = glob '*';
> foreach my $folder (@folders)
> {
> print "Converting $folder...\n";
> convert_folder( $folder );
> }
------------------------------
Date: Sat, 20 Sep 2003 21:04:05 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: debugging
Message-Id: <Xns93FCE077CE19Csdn.comcast@206.127.4.25>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
"superfly2" <darius_fatakia@yahoo.com> wrote in
news:bkfpl5$9aq$1@news.Stanford.EDU:
> just a general debugging question:
> i'm writing a script (web script) and i keep getting back the infamous
> Error message:
> Premature end of script headers: new_batch_convert.pl
>
> I have "use strict" and "use warnings", and I check the error log but
> that message is ALL i get. i'm trying to comment out different regions
> to get it to work that way but i was wondering if there were any other
> suggestions for approaching this. Basically, I had a working script
> that i modified and now i don't know where my bug is. If it was a
> missing semicolon or parentheses, I would get some line number
> reference right?
The excellent ptkdb debugger is wonderful for debugging CGI programs.
Google for 'ptkdb' to find it. Its documentation includes instructions for
running CGI programs under ptkdb -- you click on a link in your browser,
and ptkdb pops up on your terminal and allows you to single-step, examine
and change variables, etc.
- --
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBP20HC2PeouIeTNHoEQLpAACg+kHZnV7WLlnjmKHCeAixUlAZ5CcAnR/T
PsjY7CiSbyzIPGTDz7cVHK2e
=oAk2
-----END PGP SIGNATURE-----
------------------------------
Date: Sun, 21 Sep 2003 02:07:53 GMT
From: "Robert TV" <ducott_99@yahoo.com>
Subject: Difficulty removing element from array
Message-Id: <ZJ7bb.1004827$3C2.22437921@news3.calgary.shaw.ca>
Hi ... I'm loosing much hair over this array element removal problem i'm
having. I will describe my setup. I have a web form with a single text box
named "recipient" ... on submit, the data is passed to my delete.pl script.
In the same folder, there is a text file called "addresses.txt" This file
contains the following data:
Gerald Genry|jdpower@assoc.com
Gerry Smith|smith@yahoo.com
Robert TV|rtv@shaw.ca
Terry Valcourt|mail@viator.com
Dan Perterson|simple@yahoo.com
James Smiley|happy@hotmail.com
These are names and email addresses separated by a "|" symbol. Here is the
delete script I have so for that is not functional:
#############
#!/usr/bin/perl
use Fcntl qw(:DEFAULT :flock);
use CGI::Carp qw(fatalsToBrowser);
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$form{$name} = $value;
}
open (ADDRESSES, "<addresses.txt") or die "Can't open file: $!";
@entrys=<ADDRESSES>;
close(ADDRESSES);
foreach $entry (@entrys) {
$count++;
if ($entry eq $form{'recipient'}) {
$count--;
splice(@entrys, $count, 1);
}
}
print @entrys;
exit;
#############
If I type "Terry Valcourt|mail@viator.com" in the web form and submit,
nothing happens. When @entrys prints, it still contains all entires read
from the text file. It's the same for any name and email address grouping
entered. To match the form input to the array element, I used the "eq"
operator. It is my belief that there is no successful matching because there
is a "\n" at the end of each "$entry". So I thought I might add a "chomp
($entry);" command to the equation that would remove the "\n"s from the end
of each $entry. Below is code with the chomp:
#############
#!/usr/bin/perl
use Fcntl qw(:DEFAULT :flock);
use CGI::Carp qw(fatalsToBrowser);
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$form{$name} = $value;
}
open (ADDRESSES, "<addresses.txt") or die "Can't open file: $!";
@entrys=<ADDRESSES>;
close(ADDRESSES);
foreach $entry (@entrys) {
chomp ($entry);
$count++;
if ($entry eq $form{'recipient'}) {
$count--;
splice(@entrys, $count, 1);
}
}
print @entrys;
exit;
#############
This is where things get REALLY messed up. I go back to the web form and
type "Terry Valcourt|mail@viator.com" This time when @entrys prints, all
lines of data have been removed except "Dan Perterson|simple@yahoo.com" I've
spent hours trying to understand what is going on ... please help me see the
light!
P.S. I know most of you may look at my coding methods and laugh, bear in
mind i'm very new and still learning :-)
Robert
------------------------------
Date: Sat, 20 Sep 2003 20:05:31 -0700
From: Chief Squawtendrawpet <cs@edu.edu>
Subject: Re: Difficulty removing element from array
Message-Id: <3F6D157B.FCC01858@edu.edu>
Robert TV wrote:
> foreach $entry (@entrys) {
> $count++;
> if ($entry eq $form{'recipient'}) {
> $count--;
> splice(@entrys, $count, 1);
> }
> }
You're modifying an array while iterating over it, which seems like a bad
idea to me. If the entries are unique you could store them in a hash
instead of an array, making the deletion process very easy.
# Read entries [not tested]
while (<ADDRESSES>){
chomp; # Don't you need to remove the newlines from your entries?
$entrys{$_} = 1;
}
# Delete one
delete $entrys{$form{recipient}};
If the entries must be in an array, you could use grep() to delete those
matching $form{recipient}.
# Not tested
@entrys = grep $_ ne $form{recipient}, @entrys;
Chief S.
------------------------------
Date: 20 Sep 2003 18:31:23 -0700
From: toddrw69@excite.com (trwww)
Subject: Re: Little survey for Unix users
Message-Id: <d81ecffa.0309201731.172e8a42@posting.google.com>
Abigail <abigail@abigail.nl> wrote in message news:<slrnbmlaea.esh.abigail@alexandra.abigail.nl>...
> Steve Hémond (shemond@hotmail.com) wrote on MMMDCLXX September MCMXCIII
> in <URL:news:_muab.9341$hF3.1237617@news20.bellglobal.com>:
> -- I'm not willing to start a religious war, but, what is your prefered editor
> -- for works such as Perl programming? (Vi(m) or Emacs?)
>
>
> Real (wo)men use 'cat'. Wussies use 'ed'. Vi and Emacs are for poofs.
>
>
>
> Abigail
I like pico. cat with contol characters =0).
Todd W.
------------------------------
Date: Sun, 21 Sep 2003 03:54:12 GMT
From: Sam <samj2@austarmetro.com.au>
Subject: Re: perl lib all over the place
Message-Id: <3F6D22AE.20806@austarmetro.com.au>
ko wrote:
> "Sam" <samj@austarmetro.com.au> wrote in message
news:<3f69c8ff@news.comindico.com.au>...
>
>>Hello
>>
>>I have Perl modules all over the place and I think it would be good house
>>keeping practice to get them all in one common dir. If that is true
then how
>>can I do that?
>>
>>Or just keep adding "use lib "/my/location";" at the top of the programs?
>>
>>I have some module.pm in the following locations
>>
>>/usr/local/lib/perl/5.6.1
>>
>>/usr/lib/perl/5.6.1
>>
>>/usr/local/lib/perl5/5.8.0/i686-linux
>>
>>/usr/local/lib/perl5/5.8.0
>>
>>/usr/local/lib/perl5/site_perl/5.8.0/i686-linux
>>
>>/usr/local/lib/perl5/site_perl/5.8.0
>>
>>/usr/local/lib/perl5/site_perl
>>
>>
>>
>>thanks
>
>
> Please *don't* mess with the modules in these locations. These are the
> default (built when Perl is installed) libraries that Perl searches
> when you 'use' or 'require' a module/file, which can also be found in
> Perl's special @INC array. If you type:
>
> perl -e 'print "$_\n" foreach (@INC)'
>
> You will get the same directories listed above (actually half of the
> directories, since you seem to have two versions of Perl installed).
>
> So if you're using one of Perl's core modules or have installed other
> CPAN modules and haven't messed with the makefile, you should not need
> to "use lib '/my/location';" in your programs as stated above.
> *Usually*, you only need the 'use lib' pragma in two cases: (1)
> personal libraries, or (2) if you don't have permission (no
> root/administrator privileges) to install CPAN modules in the system
> directories.
>
> On an off topic note, I just saw your post regarding browsing the perl
> documentation. If you don't find the 'perldoc...' interface intuitive,
> may I suggest that you try http://www.perldoc.com/ ? It may be easier
> to browse the documentation in HTML, and there is documentation for
> the last six versions of Perl. The 'Perl Manpage' link takes you to
> Perl's *core* documentation.
>
> HTH - keith
in regarding to browsing the perl docs. www.perldoc.com does not support
packages which is not part of the core perl disto...correct?
if so, do I have another chance with not core modules.
I am now using $man Date::Calc and it has above 60 items in the main
array, I would like to be able to click on an item and it takes me to
more explanation about what it is and it does. it is very hard when I
cann't even search the man page of a module or can I?
------------------------------
Date: Sat, 20 Sep 2003 21:41:11 +0200
From: Stefan Rupp <st.rupp@t-online.de>
Subject: Re: Perl regular expression does not work on 5.8.0
Message-Id: <bkiagn$hcc$07$1@news.t-online.com>
Shalom!
> I would just try "The Debian way"
> and put
> export LC_ALL="POSIX"
[...]
> into /etc/profile.
Brilliant, now it works like expected.
>> The other option, to update perl, would be to go to perl 5.8.1 beta,
>> which I'd rather avoid. I'd need libdb-4.1.so for that as well.
>
> Yes, the old problem with db versions. Changing
> locale settings as a work-around should do until
> 5.8.1 stable is available on RHN.
Thanks a lot!
Regards,
Stefan
------------------------------
Date: Sun, 21 Sep 2003 03:19:45 GMT
From: Sam <samj@austarmetro.com.au>
Subject: program not being run
Message-Id: <3F6D1A9C.1000507@austarmetro.com.au>
Hello
I am getting this message every thim I try
<gdb> s
The program is not being run.
thanks
------------------------------
Date: Sun, 21 Sep 2003 03:53:46 GMT
From: Sam <samj2@austarmetro.com.au>
Subject: Re: program not being run
Message-Id: <3F6D2292.9070505@austarmetro.com.au>
Sam wrote:
> Hello
> I am getting this message every thim I try
> <gdb> s
> The program is not being run.
>
> thanks
>
This GDB was configured as "i386-linux"..."/home/username/perl/test.pl":
not in exeutable format: File format not recognized
(gdb)s
The program is not being run
(gdb)
------------------------------
Date: 20 Sep 2003 19:08:24 -0700
From: toddrw69@excite.com (trwww)
Subject: Re: referencing, closures, classes
Message-Id: <d81ecffa.0309201808.6f9c0c8b@posting.google.com>
Uri Guttman <uri@stemsystems.com> wrote in message news:<x7brtgpj4b.fsf@mail.sysarch.com>...
> >>>>> "DM" == David McDivitt <x12code-del@del-yahoo.com> writes:
>
<snip />
>
> DM> The book does have good stuff such as a whole chapter on
> DM> fundamental flow charting. It was not UML. I hate stick
> DM> people. There as another good chapter on the history of computers
> DM> and the internet. The book is not a total waste.
>
> what? this covered flow charts? what kind of dumb shit is that? anyone
> who is learning perl and knows any other language should not need flow
> charts. ewwwww!!
>
Deitel & Deitel books are used as the basis for alot of college class
curricula. My ICS & DSA I book was "C++ how to program." They are
authors of about 20 programming books. They are probably better
salesmen than programmers and authors combined.
To the OP, I recommend Oreilly books for perl programming. They get
the top notch programmers in the perl community to write for them. If
you post questions about Oreilly perl books in comp.lang.perl.* or the
perl.* groups on nntp.perl.org you'll usually get replies from the
book authors themselves. You'll notice neither of the Deitels have
responded to your posts.
I dont work for Oreilly, I'm just a satisfied customer.
Todd W.
------------------------------
Date: Sat, 20 Sep 2003 18:31:03 +0100 (BST)
From: "Dave Saville" <dave.nospam@ntlworld.com>
Subject: Re: search a string
Message-Id: <qnirfnivyyragyjbeyqpbz.hljajr0.pminews@text.news.ntlworld.com>
On Sat, 20 Sep 2003 13:35:06 GMT, J rgen Exner wrote:
>peter pilsl wrote:
>> alexanderl wrote:
>>> to check and search a particular string within a file but the string
>>> must be within <h1> </h1> tag
>>>
>>> say for example i check and search the string "Click" that is within
>>> the <h1></h1> tag. If the string is found then that string will be
>>> replace with the string "Link".
>>
>> s/<h1>Click</h1>/<h1>Link</h1>/g;
>
>Right idea but:
> syntax error at C:\tmp\t.pl line 4, near "h1>"
>
>Your command will try to replace '<h1>Click<' with 'h1>' and then there is a
>lot of garbage behind the substitution string.
>Either escape the forward slash within your RE and the replace string or
>even better use a different separator:
>
> s=<h1>Click</h1>=<h1>Link</h1>=g;
Err.. I think the OP meant finding Click *somewhere* inside an h1 tag
which of course could involve multiple lines :
<h1>
This string has Click in it
</h1>
Or any combo of the above. No - I am not that good at regex's :-)
Regards
Dave Saville
NB switch saville for nospam in address
------------------------------
Date: Sat, 20 Sep 2003 18:20:57 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: search a string
Message-Id: <dU0bb.2588$jo2.343@nwrddc03.gnilink.net>
Dave Saville wrote:
> On Sat, 20 Sep 2003 13:35:06 GMT, J rgen Exner wrote:
>>[simple approach deleted]
> Err.. I think the OP meant finding Click *somewhere* inside an h1 tag
> which of course could involve multiple lines :
>
> <h1>
> This string has Click in it
> </h1>
>
> Or any combo of the above. No - I am not that good at regex's :-)
Ok, in that case the best advise would be: use an HTML parser if you want to
parse HTML.
Contrary to popular believe parsing HTML _correctly_ is rocket science and
nobody with a sane mind would try using REs to do it.
Further details please see the FAQ.
jue
------------------------------
Date: Sat, 20 Sep 2003 14:35:26 -0400
From: Mina Naguib <spam@thecouch.homeip.net>
Subject: Re: search a string
Message-Id: <Q51bb.33302$0l4.833110@weber.videotron.net>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
alexanderl wrote:
> i would like to do the following with perl script:
>
>
>
> to check and search a particular string within a file but the string
> must be within <h1> </h1> tag
>
> say for example i check and search the string "Click" that is within the
> <h1></h1> tag. If the string is found then that string will be replace
> with the string "Link".
>
>
>
> is there a simple way to do that pls?
The simple yet error-prone way to do it is:
$data =~ s|(<h1>.*?)Click(.*?</h1>)|${1}Link$2|;
The correct way to do it is to use an HTML parser. I'm comfortable with HTML::TokeParser so that's
what I'll use:
use HTML::TokeParser;
$parser = HTML::TokeParser->new(\$data);
while ($token = $parser->get_token()) {
$rawdata = $token->[$token->[0] eq "T" ? 1 : -1];
if ($token->[0] eq "S" && $token->[1] eq "h1") {
#
# We're inside an <h1> - toggle flag
#
$insideh1 = 1;
}
elsif ($token->[0] eq "E" && $token->[1] eq "h1") {
#
# We just left an <h1> - toggle flag
#
$insideh1 = 0;
}
elsif ($token->[0] eq "T" && $insideh1) {
#
# We read text inside an <h1> </h1> - do replacement on it
#
$rawdata =~ s/Click/Link/;
}
$newdata .= $rawdata;
}
print "New data:\n\n$newdata";
It's definately a lot longer and harder to understand, but it's the correct way to do it and will
handle cumbersome HTML correctly where a simple regex will not.
For more information, see perldoc HTML::TokeParser or
http://search.cpan.org/author/GAAS/HTML-Parser-3.31/lib/HTML/TokeParser.pm
Best of luck.
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE/bJ3xeS99pGMif6wRAkR0AJ0XpTstDGA+FDv4OFd60EVH0iqoXQCeNF9f
Ros6UKj/8L0IQUlailbed58=
=crO8
-----END PGP SIGNATURE-----
------------------------------
Date: Sat, 20 Sep 2003 13:42:03 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: search a string
Message-Id: <slrnbmp7rr.nu1.tadmc@magna.augustmail.com>
Dave Saville <dave.nospam@ntlworld.com> wrote:
> On Sat, 20 Sep 2003 13:35:06 GMT, J rgen Exner wrote:
>>peter pilsl wrote:
>>> alexanderl wrote:
>>>> to check and search a particular string within a file but the string
>>>> must be within <h1> </h1> tag
>>>>
>>>> say for example i check and search the string "Click" that is within
>>>> the <h1></h1> tag. If the string is found then that string will be
>>>> replace with the string "Link".
>> s=<h1>Click</h1>=<h1>Link</h1>=g;
>
>
> Err.. I think the OP meant finding Click *somewhere* inside an h1 tag
> which of course could involve multiple lines :
>
><h1>
> This string has Click in it
></h1>
>
> Or any combo of the above. No - I am not that good at regex's :-)
Works for the data shown, can easily *not* work with other valid HTML:
s#(<h1>.*?</h1>)# $a=$1; $a=~s/Click/Link/; $a #gse;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 20 Sep 2003 20:50:28 +0200
From: "Sebastian Scholz" <mcbass@lightsphere.de>
Subject: Sending html mail with inline images
Message-Id: <bki7cu$h5c$1@newsreader2.netcologne.de>
Hi
I wrote a small script to send a html mail with inline images using
mail:sender. Sending html mails without the images works fine, but when I
try to have the images sent with the mail I only get the html and the image
attached to the mail. I used the example for the mail:sender module but that
did not work. Here is my code snippet :
sub smtpmailer{
eval {
(new Mail::Sender)
->OpenMultipart({
smtp => 'mailserver',
from => 'my\@mailadress.com',
to => 'recepients\@mailadress.com',
auth => 'LOGIN',
authid => 'mymail login',
authpwd => 'my password',
subject => 'HTML Mail TEST',
boundary => '1234567890'
})
->Part({ ctype => 'multipart/related'
})
->Part({ ctype => 'text/html',
disposition => 'attachment',
msg => $htmlfile
})
->Attach({
description => 'test gif',
ctype => 'image/gif',
encoding => 'base64',
disposition => "inline;
filename=\"testygify.gif\";\r\nContent-ID:<img1>",
file => $imgfile
})
->EndPart("multipart/related")
->Close()
}
or die "Cannot send mail: $Mail::Sender::Error\n";
}
$htmlfile and $imgfile are the pathes to the files. Well, like I said,
sending that mail works but the html page is not displayed, just attached.
Any idea what is wrong ? I am also willing to use another method, but I need
a way to login onto the smtp server.
Thanks alot.
Sebastian
------------------------------
Date: Sat, 20 Sep 2003 15:48:25 GMT
From: shb*NO*SPAM*@comporium.net (Si Ballenger)
Subject: Re: simple server
Message-Id: <3f6c7685.651940120@news.comporium.net>
On Fri, 19 Sep 2003 16:10:53 +0000 (UTC), "D Borland"
<no.name@eidosnet.co.uk> wrote:
>my perl question was how do i do that i perl, not with Apache, et cetera, or
>another server. I was wondering if perl has an ability to do that.
>
>That was what i asked wasn't it?
>
>D Borland
That was the question. Seems Tad sat on his broom stick a little
too soon. ;-)
>"Tad McClellan" <tadmc@augustmail.com> wrote in message
>news:slrnbmm6r2.gdh.tadmc@magna.augustmail.com...
>> D Borland <no.name@eidosnet.co.uk> wrote:
>>
>> > What i would like to know is there any way with perl for me to
>> > create a simple server, so i could say open a local file form the
>harddrive
>> > in my webbrowser, then click on a link to execute a perl script which
>will
>> > in turn return data to the current browser process.
>>
>>
>> Any web server will do that.
>>
>> There are many free web servers available.
>>
>> What is your Perl question?
>>
>>
>> --
>> Tad McClellan SGML consulting
>> tadmc@augustmail.com Perl programming
>> Fort Worth, Texas
>
>
>---
>This e-mail has been virus scanned and is certified virus Free.
>Checked by AVG anti-virus system (http://www.grisoft.com).
>Version: 6.0.518 / Virus Database: 316 - Release Date: 9/11/03
>
>
------------------------------
Date: Sat, 20 Sep 2003 22:07:47 -0500
From: "walala" <mizhael@yahoo.com>
Subject: SOS! how to search & replace some string to numbers in a text file?
Message-Id: <bkj4ln$aoq$1@mozo.cc.purdue.edu>
Dear all
I want to search and replace some string in input file A.txt and then output
B.txt.
The target string in A.txt is:¡°NRD=1U/X.XXE-0X¡±,(where X.XX stands for a
number, -E0X is its exponentials, for example, NRD=1U/1.84E-06)
I want to change this to ¡°NRD=Y.YYYY¡±, where Y.YYYY=1e-6/X.XXe-0X.
For example, "NRD=1U/1.84E-06" -> "NRD=0.5435"
I want to search the whole file and for all such occurence, replace then
output to B.txt.
Can anybody give me the example code on how to do this? Thanks a lot!
-Walala
------------------------------
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 5534
***************************************