[23105] in Perl-Users-Digest
Perl-Users Digest, Issue: 5326 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 7 00:05:49 2003
Date: Wed, 6 Aug 2003 21:05:09 -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 Wed, 6 Aug 2003 Volume: 10 Number: 5326
Today's topics:
confusion with foreach <bzImage@Ameritech.net>
Re: confusion with foreach <pinyaj@rpi.edu>
Re: confusion with foreach ctcgag@hotmail.com
Re: confusion with foreach <ndronen@io.frii.com>
Re: Convert UTF-8 to unicode? <flavell@mail.cern.ch>
Re: Convert UTF-8 to unicode? <jurgenex@hotmail.com>
Re: Net-Whois-IP-0.35 returning incorrect responses? <glex_nospam@qwest.net>
Re: Perl Math Syntax <krahnj@acm.org>
Problem with unwanted newline <arg@whangomatic.freeserve.co.uk>
Re: Problem with unwanted newline <blackhole@userstudy.com>
Re: Problem with unwanted newline (Tad McClellan)
Re: Renaming Files inside a GZ Zip File <nospam-abuse@ilyaz.org>
Re: Replace a word if its not in an html tag <shawn@magma.ca>
Re: Replace a word if its not in an html tag <jaspax@u.washington.edu>
Re: Replace a word if its not in an html tag (Tad McClellan)
Re: Replace a word if its not in an html tag (Tad McClellan)
Re: Replace a word if its not in an html tag <matthew.garrish@sympatico.ca>
Re: Replace a word if its not in an html tag (Tad McClellan)
Using slices with 'my' to initialize hash keys and valu <spamblock@junkmail.com>
using tr and ascii value (Dan Guzman)
Re: using tr and ascii value <bwalton@rochester.rr.com>
Re: using tr and ascii value <REMOVEsdnCAPS@comcast.net>
Re: using tr and ascii value (Tad McClellan)
very simple question (Monkey Boy)
Re: very simple question <krahnj@acm.org>
Re: very simple question (Tad McClellan)
Re: very simple question <REMOVEsdnCAPS@comcast.net>
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 06 Aug 2003 22:13:28 GMT
From: Anand S Bisen <bzImage@Ameritech.net>
Subject: confusion with foreach
Message-Id: <c4fYa.17931$Vx2.9104816@newssvr28.news.prodigy.com>
I have a small script that basically reads each element of an array
and finds the largest and smallest number in that array, it's a two
dimentional array. The way that i am traversing with my 2 dimentional
array is
my $max=0;
my $min=0;
foreach my $row (@data) {
foreach my $col (@$row) {
if ($col > $max) {
$max=$col;
}
if ($col < $min) {
$min=$col;
}
}
}
print STDERR "Maximum height of the graph ", $max, "\n";
print STDERR "Minimum height of the graph ", $min, "\n";
Everything is working as expected, but the problem arises when i want
to just omit the first entry of every column. How do i successfully
eliminate the first column of every row in this search ?
Thanks
Anand
------------------------------
Date: Wed, 6 Aug 2003 18:43:06 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: Anand S Bisen <bzImage@Ameritech.net>
Subject: Re: confusion with foreach
Message-Id: <Pine.SGI.3.96.1030806183952.473458B-100000@vcmr-64.server.rpi.edu>
[posted & mailed]
On Wed, 6 Aug 2003, Anand S Bisen wrote:
>my $max=0;
>my $min=0;
>foreach my $row (@data) {
> foreach my $col (@$row) {
> if ($col > $max) {
> $max=$col;
> }
> if ($col < $min) {
> $min=$col;
> }
> }
>}
>Everything is working as expected, but the problem arises when i want
>to just omit the first entry of every column. How do i successfully
>eliminate the first column of every row in this search ?
Well, you can iterate over the indices instead:
for my $col_idx (1 .. $#$row) {
if ($row->[$col_idx] > $max) { $max = $row->[$col_idx] }
# ...
}
Or you can cheat and use this trick:
for my $col (@$row) {
next if \$col == \$row->[0];
# max/min setting code...
}
Since $col is an alias to each element in @$row, not just a copy, a
reference to $col is the same as a reference to the element in @$row
itself. Therefore, if \$col is equal to \$row->[0], then $col must be the
first element in @$row. (This logic only holds true if $col is not a
reference itself, as I believe is the case in your code.)
--
Jeff Pinyan RPI Acacia Brother #734 2003 Rush Chairman
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: 07 Aug 2003 00:16:44 GMT
From: ctcgag@hotmail.com
Subject: Re: confusion with foreach
Message-Id: <20030806201644.294$fT@newsreader.com>
Anand S Bisen <bzImage@Ameritech.net> wrote:
> I have a small script that basically reads each element of an array
> and finds the largest and smallest number in that array, it's a two
> dimentional array. The way that i am traversing with my 2 dimentional
> array is
>
> my $max=0;
> my $min=0;
> foreach my $row (@data) {
> foreach my $col (@$row) {
> if ($col > $max) {
> $max=$col;
> }
> if ($col < $min) {
> $min=$col;
> }
> }
> }
> print STDERR "Maximum height of the graph ", $max, "\n";
> print STDERR "Minimum height of the graph ", $min, "\n";
>
> Everything is working as expected, but the problem arises when i want
> to just omit the first entry of every column. How do i successfully
> eliminate the first column of every row in this search ?
I don't vouch for the efficiency of this, but change the inner foreach
to:
foreach my $col (@$row[1..$#$row]) {
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
------------------------------
Date: 07 Aug 2003 03:57:54 GMT
From: Nicholas Dronen <ndronen@io.frii.com>
Subject: Re: confusion with foreach
Message-Id: <3f31ce42$0$191$75868355@news.frii.net>
Anand S Bisen <bzImage@ameritech.net> wrote:
ASB> I have a small script that basically reads each element of an array
ASB> and finds the largest and smallest number in that array, it's a two
ASB> dimentional array. The way that i am traversing with my 2 dimentional
ASB> array is
ASB> my $max=0;
ASB> my $min=0;
ASB> foreach my $row (@data) {
ASB> foreach my $col (@$row) {
ASB> if ($col > $max) {
ASB> $max=$col;
ASB> }
ASB> if ($col < $min) {
ASB> $min=$col;
ASB> }
ASB> }
ASB> }
ASB> print STDERR "Maximum height of the graph ", $max, "\n";
ASB> print STDERR "Minimum height of the graph ", $min, "\n";
ASB> Everything is working as expected, but the problem arises when i want
ASB> to just omit the first entry of every column. How do i successfully
ASB> eliminate the first column of every row in this search ?
Do you have warnings enabled? This should do the trick.
Note the use of -w.
#!/usr/bin/perl -w
$|++;
use strict;
my @data = ( [ 2, 1, 0 ], [ 5, 4, 3 ], [ 8, 7, 6 ] );
my ($min, $max) = (0, 0);
foreach my $row (@data) {
my $skip;
foreach my $col (@$row) {
next unless $skip++;
$max = $col if $col > $max;
$min = $col if $col < $min;
}
}
print "Maximum height of the graph: $max\n";
print "Minimum height of the graph: $min\n";
__END__
$ ./baz
Maximum height of the graph: 7
Minimum height of the graph: 0
Regards,
Nicholas
--
"Why shouldn't I top-post?" http://www.aglami.com/tpfaq.html
"Meanings are another story." http://www.ifas.org/wa/glossolalia.html
------------------------------
Date: Thu, 7 Aug 2003 01:37:41 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Convert UTF-8 to unicode?
Message-Id: <Pine.LNX.4.53.0308070035110.27486@lxplus013.cern.ch>
On Wed, Aug 6, Nigel Horne inscribed on the eternal scroll:
> I have been sent a file in UTF format,
If we're to believe your subject header, it's utf-8 (as opposed to
utf-16LE or utf-16BE or whatever...)
> that is a file with UTF characters.
utf-8 is a representation of Unicode characters. I don't know what
the term "UTF characters" would mean.
> If I cat(1) the file I correctly see the Japanese characters.
It sounds as if you have a utf-8-capable terminal, then.
> How do I display the same characters in Perl?
Not to be too trite, but you'd read them in and then you'd print them
out. Just where are you experiencing a problem?
> An "od -x" of the file looks like
> this:
>
> 0000000 a4e6 e79c a2b4
I think that's OK; I'm not too good with doing utf-8 in my head.
I don't grasp your problem yet. Where did you get so far? Are you
using Perl 5.8 ? Have you read the relevant perldoc pages? Are you
opening output and input with ":utf8"?
------------------------------
Date: Thu, 07 Aug 2003 02:30:46 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Convert UTF-8 to unicode?
Message-Id: <qRiYa.22415$td7.4652@nwrddc01.gnilink.net>
Nigel Horne wrote:
> I have been sent a file in UTF format,
Which UTF? If I'm not mistaken UTF stands for Unicode Transfer Format and it
could be any of UTF-8, UTF-16, UTF-32 and probably a few more.
> that is a file with UTF characters.
I doubt that. They are probably Unicode characters which are encoded into
some UTFormat.
> If I cat(1) the file I correctly see the Japanese
> characters.
Then probably your display driver knows how to interpret whatever encoding
you got.
> How do I display the same characters in Perl? An "od -x"
The first step would be to identify the actual encoding of your source text.
And then take it from there.
jue
------------------------------
Date: Wed, 06 Aug 2003 17:38:21 -0500
From: "J. Gleixner" <glex_nospam@qwest.net>
Subject: Re: Net-Whois-IP-0.35 returning incorrect responses?
Message-Id: <eqfYa.77$jq1.34576@news.uswest.net>
Sylvain Robitaille wrote:
> I'm trying to write a Perl script which will (among other things) look
> up the Whois information, based on an IP address it encounters, but the
> responses I'm getting from Net-Whois-IP-0.35 are not what I'm expecting,
> (though I suppose they're technically correct).
[...]
> Does anyone know how to get Net::Whois::IP to send back the response I'm
> expecting, or should I simply call my command-line whois from the script
> I'm writing? (it would of course be much cleaner to use a Perl module
> for this ...)
>
Try Net::Whois::Raw
------------------------------
Date: Thu, 07 Aug 2003 02:13:42 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Perl Math Syntax
Message-Id: <3F31B5D3.E0C7FE40@acm.org>
--Rick wrote:
>
> "John W. Krahn" <krahnj@acm.org> wrote in message
> news:3F2F59BD.A1D21C05@acm.org...
> | \"Dandy\" Randy wrote:
> | >
> | > Needs some help getting a ... well ... pretty basic math script
> | > working but the solution eludes me .... I have a text file called
> | > opened.txt ... it contains the following single line data:
> | >
> | > 2000|0|0
> | >
> | > What I am looking to do is when the script is run, I would like
> | > the second value to increase by 1 .... kind of like this:
> |
> | #!/usr/bin/perl -p
> |
> | BEGIN { ( $^I, @ARGV ) = ( '', 'opened.txt' ) }
> | s/|(\d+)|/|@{[$1+1]}|/
> |
> | __END__
>
> I couldn't figure out how this one was supposed to work, so I tried it
> and couldn't really fix it.
>
> This works though...
>
> #!/usr/bin/perl -p
>
> BEGIN { ( $^I, @ARGV ) = ( '.bak', 'opened.txt' ) }
> s/\|(\d+)\|/"|" . ($1+1) . "|"/e;
>
> __END__
>
> Can you explain your version to me? It looks like there is a lot
> there I could learn.
Sorry, I forgot to backwack the veritcal bars. :-)
#!/usr/bin/perl -p
BEGIN { ( $^I, @ARGV ) = ( '', 'opened.txt' ) }
s/\|(\d+)\|/|@{[$1+1]}|/
__END__
John
--
use Perl;
program
fulfillment
------------------------------
Date: Wed, 6 Aug 2003 23:44:22 +0100
From: Andrew R. Gillett <arg@whangomatic.freeserve.co.uk>
Subject: Problem with unwanted newline
Message-Id: <MPG.199b9515b3ebfc2f9897bd@news.cis.dfn.de>
Being a Perl newbie, I may be doing something very simple wrong here. The
following line doesn't seem to work as I expect it to:
print FILEHANDLE 'Thing:\n' . $var1 . '\n' . $var2;
The desired output (if var1 = Hello and var2 = Goodbye) is:
Thing:\nHello\nGoodbye
But what I actually get is this:
Thing:\nHello
\nGoodbye
The most likely explanation is that var1 has a newline in it (the text is
read in from a file). I tried stripping \n from the variable, it didn't
work but I'm not sure if this is the right way to do it:
$var1 =~ s/"\n"//;
--
Andrew Gillett http://argnet.fatal-design.com/
UK videogame release dates at:
http://www.release-dates.co.uk/
------------------------------
Date: Wed, 06 Aug 2003 19:38:53 -0400
From: Shawn O'Donnell <blackhole@userstudy.com>
Subject: Re: Problem with unwanted newline
Message-Id: <blackhole-2CEC04.19385306082003@news-50.giganews.com>
In article <MPG.199b9515b3ebfc2f9897bd@news.cis.dfn.de>,
Andrew R. Gillett <arg@whangomatic.freeserve.co.uk> wrote:
> The most likely explanation is that var1 has a newline in it
So did you check?
> I tried stripping \n from the variable, it didn't
> work but I'm not sure if this is the right way to do it:
>
> $var1 =~ s/"\n"//;
You don't want the quotation marks.
s/"\n"// looks for a quotation mark, then a new line, then a quotation
mark. Besides not being what you want, chances are that it's impossible
for $var1 to match it.
In any case, this looks like a problem that wants to be solved by the
chomp function.
chomp $var1;
------------------------------
Date: Wed, 6 Aug 2003 22:00:52 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Problem with unwanted newline
Message-Id: <slrnbj3g74.2e2.tadmc@magna.augustmail.com>
Andrew R. Gillett <arg@whangomatic.freeserve.co.uk> wrote:
> I tried stripping \n from the variable, it didn't
> work
perldoc -f chomp
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 6 Aug 2003 22:59:14 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Renaming Files inside a GZ Zip File
Message-Id: <bgs182$2s38$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Brian McCauley
<nobull@mail.com>], who wrote in article <u9n0em4tau.fsf@wcl-l.bham.ac.uk>:
> hymie@lactose.smart.net (hymie!) writes:
> > The only place the filename is stored is in the filename.
>
> This is untrue. The GZIP format also allows for the file name to be
> stored _in_ the file. This was used on old DOS systems so that
> WHATEVER.TIF could be compressed to WHATEVER.TIZ and then restored to
> WHATEVER.TIF. I can see no reason why anything but a DOS version of
> gunzip would care about the filename stored inside the GZIP file.
--name is a part of the published CLI.
> This, of course, has nothing to do with Perl.
Sure,
Ilya
------------------------------
Date: Wed, 06 Aug 2003 18:10:05 -0400
From: Shawn Corey <shawn@magma.ca>
Subject: Re: Replace a word if its not in an html tag
Message-Id: <N8Gcnc_KwucQ4ayiXTWJhQ@magma.ca>
Chesucat wrote:
> On 6 Aug 2003, Tim asked:
>
>
>>What would the regular expression be to replace the word "body" in an
>>html document as long as it's not in between < and > so it doesn't
>>replace the actual body tag or anything else with body?
>>
>>Thanks in advance for any help.
>>
>>-Tim
>
>
> s/body//g
>
Try:
s/([^<])body([^>])/${1}new_body$2/g; # not begining or end of line
s/^body([^>])/new_body$1/; # beginning of line
s/([^<])body$/${1}new_body/; # end of line
------------------------------
Date: Wed, 6 Aug 2003 15:44:09 -0700
From: JS Bangs <jaspax@u.washington.edu>
Subject: Re: Replace a word if its not in an html tag
Message-Id: <Pine.A41.4.56.0308061528500.105312@dante23.u.washington.edu>
Chesucat sikyal:
> On 6 Aug 2003, Tim asked:
>
> > What would the regular expression be to replace the word "body" in an
> > html document as long as it's not in between < and > so it doesn't
> > replace the actual body tag or anything else with body?
> >
> > Thanks in advance for any help.
> >
> > -Tim
>
> s/body//g
No, that will replace 'body' even if it *is* inside angle brackets. And it
will replace 'body' when it's a substring of another word. Better would be
s/([^<|<\/])\bbody\b/$1/g
which appears to do what you want.
To the OP: Better yet would be to read
http://www.perldoc.com/perl5.6/pod/perlre.html so you can understand what
this means.
--
Jesse S. Bangs jaspax@u.washington.edu
http://students.washington.edu/jaspax/
http://students.washington.edu/jaspax/blog
Jesus asked them, "Who do you say that I am?"
And they answered, "You are the eschatological manifestation of the ground
of our being, the kerygma in which we find the ultimate meaning of our
interpersonal relationship."
And Jesus said, "What?"
------------------------------
Date: Wed, 6 Aug 2003 17:47:59 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Replace a word if its not in an html tag
Message-Id: <slrnbj31cv.213.tadmc@magna.augustmail.com>
Tim <tim.cavins@sitel.com> wrote:
> What would the regular expression be to replace the word "body" in an
> html document as long as it's not in between < and >
What you seek cannot be done reliably with a pattern match.
You should use a module that understands HTML for processing HTML.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 6 Aug 2003 17:55:19 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Replace a word if its not in an html tag
Message-Id: <slrnbj31qn.213.tadmc@magna.augustmail.com>
Shawn Corey <shawn@magma.ca> wrote:
> Chesucat wrote:
>> On 6 Aug 2003, Tim asked:
>>>so it doesn't
>>>replace the actual body tag or anything else with body?
>> s/body//g
Silly attempt #1.
Changes "<body>" into "<>".
It appears that you did not even read the problem specification
before offering your "answer".
> Try:
> s/([^<])body([^>])/${1}new_body$2/g; # not begining or end of line
Silly attempt #2.
Changes <img src="nobody"> into <img src="nonew_body">
[snip further silly attempts that also fail]
There is no such thing as "lines" in HTML. If you think in terms
of lines when processing HTML then you are not thinking correctly.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 6 Aug 2003 22:30:28 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Replace a word if its not in an html tag
Message-Id: <8RiYa.1122$ox5.163305@news20.bellglobal.com>
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnbj31qn.213.tadmc@magna.augustmail.com...
>
> > Try:
> > s/([^<])body([^>])/${1}new_body$2/g; # not begining or end of line
>
>
> Silly attempt #2.
>
> Changes <img src="nobody"> into <img src="nonew_body">
>
Sadly, nothing is 100% when it comes to unstructured html, not even the
oft-cited parser modules. Makes you wonder why they bother with the DTDs
when Microsoft and Netscape have done everything they can to accomodate bad
tagging.
Matt
It's free, use it: http://validator.w3.org/
------------------------------
Date: Wed, 6 Aug 2003 21:56:44 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Replace a word if its not in an html tag
Message-Id: <slrnbj3fvc.2e2.tadmc@magna.augustmail.com>
JS Bangs <jaspax@u.washington.edu> wrote:
> Chesucat sikyal:
>> On 6 Aug 2003, Tim asked:
>>
>> > What would the regular expression be to replace the word "body" in an
>> > html document as long as it's not in between < and > so it doesn't
>> > replace the actual body tag or anything else with body?
> Better would be
to give up on trying to do it with a pattern match.
> s/([^<|<\/])\bbody\b/$1/g
^^^^^^^^
This does not do what you think it does, it is exactly equivalent to:
s/([^\/|<])\bbody\b/$1/g
and
s/([^<\/|])\bbody\b/$1/g
and
s/([^|\/<])\bbody\b/$1/g
the order of characters in a character class does not matter,
neither does repeating a character.
> which appears to do what you want.
It does not appear that way to me.
<img src="body"> becomes <img src=""> with your code
We were supposed to leave it alone when it was inside of a tag.
<p>See body.doc</p> becomes <p>See .doc</p>
It is not clear what we were supposed to do in that case. Poor spec.
> To the OP: Better yet would be to read
> http://www.perldoc.com/perl5.6/pod/perlre.html so you can understand what
> this means.
JS Bangs should re-read too, it would appear. :-)
Along with this Perl FAQ:
How do I remove HTML from a string?
which gives some truly tricky cases rather than just the somewhat
obvious ones that trip up all of the code in this thread so far.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 6 Aug 2003 19:20:10 -0700
From: "David Oswald" <spamblock@junkmail.com>
Subject: Using slices with 'my' to initialize hash keys and values.
Message-Id: <vj3e20dh1do3e4@corp.supernews.com>
I have the following piece of code which works (meaning, does what I
expect):
#!/usr/bin/perl
use strict;
use warnings;
my %translation;
@translation {"A" .. "Z", 0 .. 9, ",", "?", "."} =
qw/.- -... -.-. -.. . ..-. --. .... .. .--- -.- .-..
-- -. --- .--. --.- .-. ... - ..- ...- .-- -..-
-.-- --.. ----- .---- ..--- ...-- ....- ..... -....
--... ---.. ----. --..-- ..--.. .-.-.-/;
foreach (sort keys %translation) {
print "$_ = $translation{$_}\n";
}
The output is a list of alphanumerics, and punctuation, and its morse code
representation.
I'm not really interested in the output, but use it just to verify that I've
loaded my hash as desired.
Now I would like to tighten the code just a little. In particular, it seems
un-Perlish to not be able to declare the hash and assign its key/value pairs
all in one statement.
But I cannot seem to find the way of declaring a hash while referring to it
as an array for the purpose of assigning a list of keys and a list of values
to it, all in one statement.
It doesn't seem right to say:
my @%translation .......
And of course that just gets me a bunch of syntax errors.
As does:
my %(@translation) {......
Is it possible to do what I'm considering, all in one nice slightly ugly
statement?
I've looked through the perldocs on hashes, slices, and a few other places,
but I'm just not hitting on an example that turns on my lightbulb.
Any comments and suggestions would be welcomed.
Thanks
Dave
------------------------------
Date: 6 Aug 2003 17:46:02 -0700
From: dan@danguzman.com (Dan Guzman)
Subject: using tr and ascii value
Message-Id: <ddf15003.0308061646.6c037d1f@posting.google.com>
I'm updating a process that reads in text file from a mainframe
extract. The script reads and parses out this file and creates html
documents from this data. I'm having a problem when the mainframe put
in a certain character '' the perl script stops running. It's values
are:
hex - 1a
dec - 26
oct - 032
How do I replace these types of characters? Thanks,
Dan
........
while($mLine=<INPUTFILE>) {
chomp($mLine);
$mLine =~tr/<>/ /; #-replaces <> with a space .
$mLine =~tr/\26/ /;
print $mLine;
if (substr($mLine,0,12) eq "START-REC!!!") {
#- Parse columns and insert to table!
($mTag,$mticket) = split /!!!/,$mLine;
$mticket=~ s/^\s*(.*?)\s*$/$1/;
$mText = "<pre><b><font size=4 color=blue>Ticket :
$mticket</font>\n<font size=1 color=blue>Last Mainframe
Synchronization: $mLastUpdate</font>\n\n</b>";
} elsif (substr($mLine,0,13) eq "!!!END-REC!!!") {
$mText=$mText."\n<b><font size=1 color=blue>Last Mainframe
Synchronization: $mLastUpdate</font></b></pre>";
#- Write $mText to file using the ticket nnumber as filename.
&loadTicketData($mticket,$mText);
print "$mticket\n";
} else {
$mText=$mText.$mLine."\n";
}
}
close(INPUTFILE);
------------------------------
Date: Thu, 07 Aug 2003 01:11:04 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: using tr and ascii value
Message-Id: <3F31A718.40206@rochester.rr.com>
Dan Guzman wrote:
...
> hex - 1a
> dec - 26
> oct - 032
>
> How do I replace these types of characters? Thanks,
>
> Dan
...
> $mLine =~tr/\26/ /;
Did you look in the docs, specifically:
perldoc perlop
? There it will tell you that something like:
$mLine =~ tr/\032/ /;
or
$mLine =~ tr/\x1a/ /;
should work.
...
--
Bob Walton
------------------------------
Date: Wed, 06 Aug 2003 20:38:35 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: using tr and ascii value
Message-Id: <Xns93CFDC0641BE4sdn.comcast@206.127.4.25>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
dan@danguzman.com (Dan Guzman) wrote in
news:ddf15003.0308061646.6c037d1f@posting.google.com:
> I'm updating a process that reads in text file from a mainframe
> extract. The script reads and parses out this file and creates html
> documents from this data. I'm having a problem when the mainframe put
> in a certain character '' the perl script stops running. It's values
> are:
>
> hex - 1a
> dec - 26
> oct - 032
>
> How do I replace these types of characters? Thanks,
> ........
> $mLine =~tr/\26/ /;
Close. Backslash-escaping doesn't work in decimal. You can either use
octal:
$mLine =~ tr/\032/ /;
or hex:
$mLine =~ tr/\x1a/ /;
- --
Eric
$_ = reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBPzGtZmPeouIeTNHoEQJUIQCfbvVcljOeyDKYYJ7V7hua0Q3Z9V4AoLcB
5lHA8bKsv7MgaACKJorxqX1T
=PiEV
-----END PGP SIGNATURE-----
------------------------------
Date: Wed, 6 Aug 2003 22:05:11 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: using tr and ascii value
Message-Id: <slrnbj3gf7.2e2.tadmc@magna.augustmail.com>
Dan Guzman <dan@danguzman.com> wrote:
> I'm updating a process that reads in text file from a mainframe
> extract.
What OS is your Perl program running on?
> I'm having a problem when the mainframe put
> in a certain character '' the perl script stops running.
If your program is running on an OS whose filesystem makes
a distinction between "text" and "binary" files (like Windows),
then:
perldoc -f binmode
might fix it.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 6 Aug 2003 18:17:43 -0700
From: phase00@hotmail.com (Monkey Boy)
Subject: very simple question
Message-Id: <c3e86812.0308061717.7155d5cb@posting.google.com>
How do I initialise (assign value of 0) to multiple variables without
having to manually specify each one.
ie.
$a = 0;
$b = 0;
$c = 0;
$d = 0;
..etc
How to simplify this -
FILE is a mail log file, where I have to repeat the following regex on
multiple email address. I want to have all the email addresses in an
array where I can just call it up on just a single step in the while
loop instead of copying the below line multiple times per email
address.
while (<FILE>){
chomp;
if(/amavis/ && /Passed/ && ! /\<\>/ &&
/\-\>\s\<me\@emailaddress.com\>/i){
$a++;
}
Thanks (:
MB
------------------------------
Date: Thu, 07 Aug 2003 02:23:58 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: very simple question
Message-Id: <3F31B83C.847A5B9C@acm.org>
Monkey Boy wrote:
>
> How do I initialise (assign value of 0) to multiple variables without
> having to manually specify each one.
>
> ie.
> $a = 0;
> $b = 0;
> $c = 0;
> $d = 0;
> ..etc
$a = $b = $c = $d = 0;
Or:
( $a, $b, $c, $d ) = (0) x 4;
John
--
use Perl;
program
fulfillment
------------------------------
Date: Wed, 6 Aug 2003 22:12:06 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: very simple question
Message-Id: <slrnbj3gs6.2e2.tadmc@magna.augustmail.com>
Monkey Boy <phase00@hotmail.com> wrote:
> Subject: very simple question
Please put the subject of your article in the Subject of your article!
> How do I initialise (assign value of 0) to multiple variables without
> having to manually specify each one.
I do not know how to initialize a variable without specifying
what variable it is that is to be initialized...
> ie.
> $a = 0;
> $b = 0;
> $c = 0;
> $d = 0;
... but I do know how to do it better than that at least:
$a = $b = $c = $d = 0;
> if(/amavis/ && /Passed/ && ! /\<\>/ &&
^ ^
^ ^
> /\-\>\s\<me\@emailaddress.com\>/i){
^ ^ ^ ^
^ ^ ^ ^
None of those backslashes are needed.
Angle brackets and hyphens are not special in regular expressions.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 06 Aug 2003 22:42:50 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: very simple question
Message-Id: <Xns93CFF1160A0ABsdn.comcast@206.127.4.25>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
phase00@hotmail.com (Monkey Boy) wrote in
news:c3e86812.0308061717.7155d5cb@posting.google.com:
> How do I initialise (assign value of 0) to multiple variables without
> having to manually specify each one.
>
> ie.
> $a = 0;
> $b = 0;
> $c = 0;
> $d = 0;
> ..etc
As with many things in Perl, there are several ways:
$a = $b = $c = $d = 0;
($a, $b, $c, $d) = (0, 0, 0, 0);
$_ = 0 for $a, $b, $c, $d;
And probably others.
- --
Eric
$_ = reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBPzHKhWPeouIeTNHoEQIRjgCdHYcmeez8bWNaVl37krGgbIuh2i8AoO0C
KZIR7iZjy4cWv5vzbqaHhTvv
=TA4P
-----END PGP SIGNATURE-----
------------------------------
Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re:
Message-Id: <3F18A600.3040306@rochester.rr.com>
Ron wrote:
> Tried this code get a server 500 error.
>
> Anyone know what's wrong with it?
>
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {
(---^
> dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
...
> Ron
...
--
Bob Walton
------------------------------
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 5326
***************************************