[28477] in Perl-Users-Digest
Perl-Users Digest, Issue: 9841 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 13 06:10:18 2006
Date: Fri, 13 Oct 2006 03:10: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 Fri, 13 Oct 2006 Volume: 10 Number: 9841
Today's topics:
Probs with nested conditions ultimard@yahoo.com
Re: Probs with nested conditions <mritty@gmail.com>
Re: Probs with nested conditions <tadmc@augustmail.com>
Re: Probs with nested conditions (reading news)
Reading substitution patterns from file <maciej.ogrodniczuk@gmail.com>
Re: Reading substitution patterns from file anno4000@radom.zrz.tu-berlin.de
Re: Reading substitution patterns from file <peace.is.our.profession@gmx.de>
Regarding junk characters !Help <Gaurav.Saikia@gmail.com>
Re: Standard output problem wesphillips@gmail.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 12 Oct 2006 17:20:21 -0700
From: ultimard@yahoo.com
Subject: Probs with nested conditions
Message-Id: <1160698821.358981.196440@i3g2000cwc.googlegroups.com>
I am a little rusty w/ perl, haven't done it in a while, but this is
the trouble I am having..
I am having trouble getting to the 3rd condition, it seems to be
ignoring the 3rd condition
if ( $ar{$ar}{loc} eq 'HBR' and \
$ar{$ar}{ar_typ} eq 'DMX' and $ar{$ar}{tier} = 146 )
{ $HBR_pr += $ar{$ar}{fr_r5}; }
Basically testing for 3 or more conditions and then summing up an
element in a hash of hashes.
Any ideas will be appreciated ..
------------------------------
Date: 12 Oct 2006 18:14:56 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Probs with nested conditions
Message-Id: <1160702096.211345.24630@e3g2000cwe.googlegroups.com>
ultimard@yahoo.com wrote:
> I am a little rusty w/ perl, haven't done it in a while, but this is
> the trouble I am having..
>
> I am having trouble getting to the 3rd condition, it seems to be
> ignoring the 3rd condition
>
>
> if ( $ar{$ar}{loc} eq 'HBR' and \
That slash doesn't belong there. I'm surprised you didn't get a
compilation error with it there.
> $ar{$ar}{ar_typ} eq 'DMX' and $ar{$ar}{tier} = 146 )
This says to set $ar{$ar}{tier} to 146, and then to check if the value
of that assignment (which will be 146) is true. If you meant to
compare $ar{$ar}{tier} to 146 to test for equality, you meant the ==
operator, not the = operator.
Paul Lalli
------------------------------
Date: Thu, 12 Oct 2006 20:19:40 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Probs with nested conditions
Message-Id: <slrneitqdc.74d.tadmc@magna.augustmail.com>
ultimard@yahoo.com <ultimard@yahoo.com> wrote:
> I am having trouble getting to the 3rd condition,
There are not 3 conditions.
There are 2 conditions...
> it seems to be
> ignoring the 3rd condition
>
>
> if ( $ar{$ar}{loc} eq 'HBR' and \
> $ar{$ar}{ar_typ} eq 'DMX' and $ar{$ar}{tier} = 146 )
^
^
... and 1 assignment.
The operator for testing numeric equality is ==
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 13 Oct 2006 03:03:22 GMT
From: "Mumia W. (reading news)" <paduille.4059.mumia.w@earthlink.net>
Subject: Re: Probs with nested conditions
Message-Id: <_lDXg.13159$UG4.11306@newsread2.news.pas.earthlink.net>
On 10/12/2006 07:20 PM, ultimard@yahoo.com wrote:
> I am a little rusty w/ perl, haven't done it in a while, but this is
> the trouble I am having..
>
> I am having trouble getting to the 3rd condition, it seems to be
> ignoring the 3rd condition
>
>
> if ( $ar{$ar}{loc} eq 'HBR' and \
There's no need for the backslash.
> $ar{$ar}{ar_typ} eq 'DMX' and $ar{$ar}{tier} = 146 )
change '= 146' to '== 146'
> { $HBR_pr += $ar{$ar}{fr_r5}; }
>
> Basically testing for 3 or more conditions and then summing up an
> element in a hash of hashes.
>
> Any ideas will be appreciated ..
>
Read "perldoc perlsyn" and "perldoc perlop"
HTH
--
Mumia W.
paduille.4059.mumia.w@earthlink.net
This is a temporary e-mail to help me catch some s-p*á/m.
------------------------------
Date: 13 Oct 2006 02:32:57 -0700
From: "Orangutan" <maciej.ogrodniczuk@gmail.com>
Subject: Reading substitution patterns from file
Message-Id: <1160731977.107034.147260@k70g2000cwa.googlegroups.com>
Hello,
I would like to read the substitution patterns from file - and I cannot
get it working. The problem is identical to the one which was already
asked here long time ago by Fotis Jannidis (cited below), but has not
been answered yet.
Does anyone have any idea whether it is at all possible (should be,
since it is exactly what Perl is doing while executing scripts that
contain patterns)?
Thanks for help,
Maciek
=======================
Maybe somenone can help me with the following problem: A replace
operation works differently depending on whether I declare the
substitution patterns in the script file or read them in from another
file.
What I want to do is this: I want to read in the patterns for a
replace
operation. The patterns are stored in the file pattern.ctr this way
oldpattern:: ::newpattern
It all works fine, but if I use metacharacters in my pattern, they
are interpolated in oldpattern but not in newpattern.
The same script works, when the variables are declared directly. What
is happening?
Here is my code.
The content of pattern.ctr is
\n:: ::<\/p>\n<p>
----------------------
open (INPUT,"file.in");
open (OUTPUT,">file.out");
open (CONTROL,"pattern.ctr");
$control = <CONTROL>;
($oldstring, $newstring) = split (/:: ::/,$control);
chop $newstring;
while ($line = <INPUT>) {
$line =~ s/$oldstring/$newstring/g;
print OUTPUT $line;
}
-------------------------
I read the manual and looked into my perl books. This is what I
already tried:
Eval the variables $oldstring and $newstring.
Used all options possible with s//
Used different forms of "" '' in pattern.ctr and the script.
Marked the "\" in the pattern.ctr as "\\" and replaced it after
reading with "\"
Even with something like
print ("Oldstring = $oldstring. Newstring = $newstring");
one can see, that the "\n" in the variables ist
not interpolated. What can I do.
BTW: I am using Perl with DOS and tried Bigperl 4.x and Ilya's
OS/2 port with the same results.
And a second question: Can variables be used with the options of
s// like s/oldpattern/newpattern/$ignorecase? The manual just mentions
the interpolation inside the patterns.
Probably this is all very simple but I am stuck.
Thanks in advance for your help
Fotis Jannidis
Institut fuer Deutsche Philologie
Universitaet Muenchen
Germany
------------------------------
Date: 13 Oct 2006 09:41:53 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Reading substitution patterns from file
Message-Id: <4p95b1Fhos8tU2@news.dfncis.de>
Orangutan <maciej.ogrodniczuk@gmail.com> wrote in comp.lang.perl.misc:
> Hello,
>
> I would like to read the substitution patterns from file - and I cannot
> get it working. The problem is identical to the one which was already
> asked here long time ago by Fotis Jannidis (cited below), but has not
> been answered yet.
>
> Does anyone have any idea whether it is at all possible (should be,
> since it is exactly what Perl is doing while executing scripts that
> contain patterns)?
Unfortunately the question you cite doesn't explain the problem very
clearly.
> =======================
>
> Maybe somenone can help me with the following problem: A replace
> operation works differently depending on whether I declare the
> substitution patterns in the script file or read them in from another
> file.
>
> What I want to do is this: I want to read in the patterns for a
> replace
> operation. The patterns are stored in the file pattern.ctr this way
> oldpattern:: ::newpattern
>
> It all works fine, but if I use metacharacters in my pattern, they
> are interpolated in oldpattern but not in newpattern.
> The same script works, when the variables are declared directly. What
> is happening?
The left side of a substitution is a regular expression, the right
side is a normal string. The two have wildly different expansion
characteristics for metacharacters, so it's no wonder they behave
differently.
Show a code example that demonstrates the behavior you want to
change and explain how your want it to behave instead. Then we
can talk.
Anno
> Here is my code.
> The content of pattern.ctr is
> \n:: ::<\/p>\n<p>
>
> ----------------------
> open (INPUT,"file.in");
> open (OUTPUT,">file.out");
> open (CONTROL,"pattern.ctr");
>
>
> $control = <CONTROL>;
> ($oldstring, $newstring) = split (/:: ::/,$control);
> chop $newstring;
>
>
> while ($line = <INPUT>) {
> $line =~ s/$oldstring/$newstring/g;
> print OUTPUT $line;
> }
>
> -------------------------
> I read the manual and looked into my perl books. This is what I
> already tried:
> Eval the variables $oldstring and $newstring.
> Used all options possible with s//
> Used different forms of "" '' in pattern.ctr and the script.
> Marked the "\" in the pattern.ctr as "\\" and replaced it after
> reading with "\"
>
> Even with something like
> print ("Oldstring = $oldstring. Newstring = $newstring");
> one can see, that the "\n" in the variables ist
> not interpolated. What can I do.
> BTW: I am using Perl with DOS and tried Bigperl 4.x and Ilya's
> OS/2 port with the same results.
> And a second question: Can variables be used with the options of
> s// like s/oldpattern/newpattern/$ignorecase? The manual just mentions
> the interpolation inside the patterns.
> Probably this is all very simple but I am stuck.
> Thanks in advance for your help
>
> Fotis Jannidis
> Institut fuer Deutsche Philologie
> Universitaet Muenchen
> Germany
>
------------------------------
Date: Fri, 13 Oct 2006 11:55:16 +0200
From: Mirco Wahab <peace.is.our.profession@gmx.de>
Subject: Re: Reading substitution patterns from file
Message-Id: <egno2k$n8b$1@mlucom4.urz.uni-halle.de>
Thus spoke Orangutan (on 2006-10-13 11:32):
> Does anyone have any idea whether it is at all possible (should be,
> since it is exactly what Perl is doing while executing scripts that
> contain patterns)?
It does what you tell it to do ...
> The content of pattern.ctr is
> \n:: ::<\/p>\n<p>
Change this to:
1:|
2:|:: ::</p>
3:|<p>
(line numbers only given for clarity)
-> start with a "real" \n
-> then, bring in your designator :: ::
-> then, give the substitution stuff,
again with a real(!) \n
> ----------------------
> open (INPUT,"file.in");
> ...
> ...
Change this to:
use strict;
use warnings;
open (my $inhandle, '<', 'file.in');
open (my $ctrlhandle, '<', 'pattern.ctr');
open (my $outhandle, '>', 'file.out');
my $control = do { local $/, <$ctrlhandle> };
my ($oldstring, $newstring) = split /:: ::/, $control;
chomp $newstring;
while (my $line = <$inhandle>) {
$line =~ s/$oldstring/$newstring/gs;
print $outhandle $line;
}
and try again.
I'm not sure what your input looks like,
but the regular expression might need
the /s or /m modifier, dependent of
what really to do (especially with
newlines involved in the substitutions).
Regards
Mirco
------------------------------
Date: 13 Oct 2006 02:59:57 -0700
From: "Gaurav" <Gaurav.Saikia@gmail.com>
Subject: Regarding junk characters !Help
Message-Id: <1160733597.660924.243350@k70g2000cwa.googlegroups.com>
Hi,
I am using the following script to read a text file and write it into
another text file.
Below is a sample of this :
open(TESTFILE,$textFilename);
open(RECORDVALUES,">$outdatafile");
while(<TESTFILE>)
{
print RECORDVALUES $_;
}
close (TESTFILE);
close (RECORDVALUES);
The following is the sample text file.
000.50 000.90 BBBBB AAAA NO 14 NNN EEEE UUUUU
000.63 001.03 BBBBBbbb XXXXX NO 1 HOTEL YYYYYYYYU
000.60 001.56 XXXX RMH NO 299 AAA BBBBBB CCCCCC
000.70 001.49 DDDDDDDD TTTTT NO 254 AAA BBBBBB CCCCCC
000.70 001.47 DDDDDDDD TTTTT NO 248/249 AAA BBBBBB CCCCCC
The problem is I cannot write the whole file, the process ended when it
reaches the char (it is a junk char ASCII value is 20). How to I read
the whole text file and write it into new text file. help me.
-best regards,
Gsec
------------------------------
Date: 12 Oct 2006 17:01:13 -0700
From: wesphillips@gmail.com
Subject: Re: Standard output problem
Message-Id: <1160697673.678376.178800@b28g2000cwb.googlegroups.com>
On Oct 12, 10:47 am, sys...@sumire.eng.sun.com (Chris Mattern) wrote:
> In article <1160598910.311902.207...@h48g2000cwc.googlegroups.com>,
>
>
>
>
>
> wesphill...@gmail.com wrote:
> >I have a perl script, it is very basic:
>
> >#!/usr/bin/perl -w
> >#test.pl
> >print "test\n";
>
> >The test.pl file is executable (permissions are 755). If I run this
> >script like this:
> >perl ./test.pl
>
> >I get the expected output, but if I run it like this:
>
> >./test.pl
>
> >I don't get anything at all. I have induced errors into the script to
> >see if I get the error messages, but I still get nothing. If I run the
> >script with the errors by explicitly calling perl, I see the error
> >output like I expect to. I have a second script in the same directory
> >that DOES work when called directly, so I don't know what could be
> >wrong. I have also changed the first line so that it looks like this:
>
> >#!/usr/bin/perly -w
>
> >and I get the expected error from bash stating that it cannot find the
> >interpreter called "perly"
>
> >Any ideas?Start out by making your command line the exact same as your #!. What do
> you get when you try:
>
> /usr/bin/perl -w ./test.pl
>
That worked fine. The only time I had problems was when I tried to run
it directly. I further narrowed it down to a specific directory. If the
file was placed in the directory(or created there) it wouldn't work. If
the exact same script was created in a different directory, it ran
fine. I doublechecked and there are no sticky bits set for the
Directory, but that wouldn't really cause this anyway...At this point I
don't think that it is a Perl problem, but instead is a Linux problem.
I decided to get away from this problem altogether and rebuilt the
machine from scratch. FYI, this problem occurred on a Dell PowerEdge
server that had Redhat Enterprise Linux Pre-installed on it from Dell.
The didn't even ship the install cd's. While I was trouobleshooting
this, I discovered that Dell even put the wrong OS on the server. This
is a Dual Xeon 64-bit server, but they put the i686 system on it. When
I rebuilt this machine with the x86_64 install, everything ran fine. If
anyone happens to run across this problem like I did, do a 'uname -a'
and see what it says after the kernel version...If it says i686 and you
have 64 bit processors, getting the correct OS would be the first thing
to try....
> ?
>
> --
> Christopher Mattern
>
> "Which one you figure tracked us?"
> "The ugly one, sir."
> "...Could you be more specific?"- Hide quoted text -- Show quoted text -
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 9841
***************************************