Edward WIJAYA
Nov 9 2004, 02:02 PM
On Tue, 9 Nov 2004 09:28:10 -0000, Murphy, Ged (Bolton)
<[Email Removed]> wrote:
QUOTE |
Ajey Kulkarni wrote:
Hmmm...Whenever you pass array AND a variable with array being first, the subroutine takes the variable and appends to array.
Make sure you pass var first,followed by array. There is no need to complicate with the array ref IMHO.
What if you want to pass 2 or more arrays? Will the proceeding arrays be appended to the previous?
Is this a case when you must pass by reference?
|
Yes, I have asked the same question.
Please refer to this link:
http://groups.google.com/groups?hl=en&lr=&....sg%26rnum%3D20Regards,
Edward WIJAYA
SINGAPORE
Joseph Paish
Nov 9 2004, 05:40 PM
On Tuesday 09 November 2004 08:41, Bob Showalter wrote:
QUOTE |
Joseph Paish wrote: just a short followup to my earlier message about the $. line number variable. when i enter a print statement as shown below, it prints the correct line number (starting at 1), but still never enters the if() structure.
for the sake of understanding how to correctly use this variable, i would really like to get this code working. if i can't, then i will use one of the workarounds that others on this list have suggested to me.
is there something special about the way the if() structure has to be phrased, other than the way i have it?
thanks
joe
while (<fh1>) { chomp ;
print $. ; # prints correct line numbers starting at 1 print "n" ; print $_ ; # prints each line of input file, starting at 1 print "n" ;
if ($. == 1 ) { # is this phrased correctly??? my @initial_values = split / /, $_ ; # process intial values here }
if ($. > 1) { #process subsequent values here }
} # end of while loop
I don't see any problem with the code as you've posted it. Here's a self-contained example using the same tests you're using. Does this example produce the same output for you as for me?
Script:
================CUT================== #!/usr/bin/perl
while (<DATA>) { print "Line $. is $_"; if ($. == 1) { print "First if() block enteredn"; } if ($. > 1) { print "Second if() block enteredn"; } }
__DATA__ First Second Third ================CUT==================
Output:
Line 1 is First First if() block entered Line 2 is Second Second if() block entered Line 3 is Third Second if() block entered
|
unfortunately(?), yes, it does give me the same output.
BTW, i think i may have found out what is giving me the strange line numbers
in the debugger under emacs. it seems that when i enter "p $." at the
debugger prompt, it displays whatever line number the debugger just printed
out. for example, if i have 17 debugger prompts before i issue the "p $."
command, it will display 17 instead of the line number of the file i am
reading at the time (which should be 1 if i just started reading the file).
ok, now this is getting strange. i inserted some print statements in my
large script, and they showed that in fact, i had been entering the first
if() structure all along. the debugger was showing me bypassing it and going
straight to the second one. maybe based on the bogus $. values that the
debugger thought were accurate? (see previous paragraph)
anyway, except for the debugger not working properly under emacs, i guess
there is no problem with the "if ($. == 1) structure . unfortunately, i have
grown to depend on the debugger to help me spot logic errors in my code. i
guess i am going to have to go back to simple print statements or run it from
the commandline where i *just* found out that it gives me the correct output.
--------
i just ran the debugger under emacs against your script above and got the
following output :
Line 2 is First
Second if() block entered
Line7 is Second
Second if() block entered
Line12 is Third
Second if() block entered
i didn't bother typing all the "DB<1> s" prompts that i used to single step
my way through the code, but they do exist on the actual emacs screen.
---------------------
sorry for the length of this post, but i have been trying things out and
describing the results as i get them. maybe this will help someone else
using the emacs/debugger combination and not getting the results that they
know(?) they should get.
joe
Paul Johnson
Nov 9 2004, 06:33 PM
On Tue, Nov 09, 2004 at 11:40:30AM -0600, Joseph Paish wrote:
QUOTE |
BTW, i think i may have found out what is giving me the strange line numbers in the debugger under emacs. it seems that when i enter "p $." at the debugger prompt, it displays whatever line number the debugger just printed out. for example, if i have 17 debugger prompts before i issue the "p $." command, it will display 17 instead of the line number of the file i am reading at the time (which should be 1 if i just started reading the file).
ok, now this is getting strange. i inserted some print statements in my large script, and they showed that in fact, i had been entering the first if() structure all along. the debugger was showing me bypassing it and going straight to the second one. maybe based on the bogus $. values that the debugger thought were accurate? (see previous paragraph)
anyway, except for the debugger not working properly under emacs, i guess there is no problem with the "if ($. == 1) structure . unfortunately, i have grown to depend on the debugger to help me spot logic errors in my code. i guess i am going to have to go back to simple print statements or run it from the commandline where i *just* found out that it gives me the correct output.
|
You don't tell us which version of perl you are running, which is always
helpful in situations such as this, but my guess is that it is ancient.
There was a bug in perl5.6.0 and earlier versions of perl which would
cause this behaviour. The bug was fixed by this patch, over four years
ago:
http://public.activestate.com/cgi-bin/perlbrowse?patch=6023If I am correct, and you are running 5.6.0 or earlier, I suggest you
upgrade in order to fix this problem and many others you might
encounter. The latest maintenance release is 5.8.5 - I recommend it.
--
Paul Johnson - [Email Removed]
http://www.pjcj.net
William C. Bruce
Nov 9 2004, 07:41 PM
[Email Removed] (Denham Eva) wrote in
news:[Email Removed]:
QUOTE |
Hello Gurus, In a script I have a piece of code as such:- ************* snip************** my $filedate =~ s/(d+)//g; ************* snip end ******* The data I am parsing looks as such :- ********** DATA ************
C:/directory/MSISExport_20040814.csv
C:/directory/MSISExport_20040813.csv
.
C:/directory/MSISExport_20030501.csv
********** DATA end ********* Now I am actually trying to dump everything except the date or numerals as such :- 20040814
Can someone help me with that regex? I am having a frustrating time of it!
Much appreciated
Denham
|
Denham,
If you have the filename in a scalar called $filename then the code to
place the date into a scalar called $filedate would be:
($filedate) = $filename =~ m|MSISExport_([0-9]+).csv|;
This places the captured value in ([0-9]+) into $filedate. This doesn't
catch an instance where the filename is malformed and that date doesn't
exist there.
Hope this helps,
Bill
Ajey Kulkarni
Nov 9 2004, 10:03 PM
If you are running this on *NIX box, plain old 'find' command is enough
too.
~A
On Tue, 9 Nov 2004, Jim wrote:
QUOTE |
The following subroutine should take an input path (Dir0), process that directory by recursively calling itself on subdirectories or processing any files it contains. The problem I am experiencing is that in the following example file structure it process Dir1 correctly, but after it returns to process the next item in the Dir0, it improperly identifies Dir2 as a file, not a directory. I am sure there is probably a better way of doing this, however, I am somewhat of a newbie to Perl and would like to understand why this code isn't working as I am expecting it to.
Do you really want or need to use your own recursive subroutine. Your best bet is probably to use File::Find Read the docs for it. Here are some good links with examples http://perlmonks.thepen.com/217166.html
http://www.adp-gmbh.ch/perl/find.html
--- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.786 / Virus Database: 532 - Release Date: 10/29/2004
-- To unsubscribe, e-mail: [Email Removed] For additional commands, e-mail: [Email Removed] <http://learn.perl.org/> <http://learn.perl.org/first-response
|
Joseph Paish
Nov 10 2004, 01:03 PM
On Tuesday 09 November 2004 11:33, Paul Johnson wrote:
QUOTE |
On Tue, Nov 09, 2004 at 11:40:30AM -0600, Joseph Paish wrote: BTW, i think i may have found out what is giving me the strange line numbers in the debugger under emacs. it seems that when i enter "p $." at the debugger prompt, it displays whatever line number the debugger just printed out. for example, if i have 17 debugger prompts before i issue the "p $." command, it will display 17 instead of the line number of the file i am reading at the time (which should be 1 if i just started reading the file).
ok, now this is getting strange. i inserted some print statements in my large script, and they showed that in fact, i had been entering the first if() structure all along. the debugger was showing me bypassing it and going straight to the second one. maybe based on the bogus $. values that the debugger thought were accurate? (see previous paragraph)
anyway, except for the debugger not working properly under emacs, i guess there is no problem with the "if ($. == 1) structure . unfortunately, i have grown to depend on the debugger to help me spot logic errors in my code. i guess i am going to have to go back to simple print statements or run it from the commandline where i *just* found out that it gives me the correct output.
You don't tell us which version of perl you are running, which is always helpful in situations such as this, but my guess is that it is ancient.
There was a bug in perl5.6.0 and earlier versions of perl which would cause this behaviour. The bug was fixed by this patch, over four years ago: http://public.activestate.com/cgi-bin/perlbrowse?patch=6023
If I am correct, and you are running 5.6.0 or earlier, I suggest you upgrade in order to fix this problem and many others you might encounter. The latest maintenance release is 5.8.5 - I recommend it.
|
first of all, thanks to all the people that have helped me with my $.
problem, both on and off this mailing list.
i guess i could have made things a lot simpler if i had mentioned the version
number to start with. i was (and still am) running 5.6.0, and have just
downloaded 5.8.5.
i will probably be starting another thread (or asking the comp.lang.perl.misc
newsgroup) about things to watch out for when installing another version on
top of an existing one.
thanks again
joe
Hey all,
I have a question about the below script I am writing/copying.
#!\serverperl
net use w: \serverperl
use Win32::Registry;
my $Register "Software\INTEL\LANDesk\VirusProtect6\CurrentVersion";
my $hkey,SubKey; #Why is this needed??
$HKEY_LOCAL_MACHINE->Open($Register,$hkey)|| die $!; # I understand
$Register, but why the use of $hkey? What is being stored in this
scalar?
$hkey->DeleteKey("Clients");
alarm(5); # Is this a correct way to pause the script?
$hkey->Create("Clients",$SubKey); #Same question here. It relates to the
declaration above obviously but what is being stored in $SubKey?
$hkey->Close();
net use w: /delete
Wouldn't it be just as easy to use:
use Win32::Registry;
my $Register "Software\INTEL\LANDesk\VirusProtect6\CurrentVersion";
$HKEY_LOCAL_MACHINE->Open($Register)|| die $!;
$hkey->DeleteKey("Clients");
$hkey->Close();
Thanks
AD
Aiguo Li
Nov 11 2004, 05:36 PM
Hi, Zeus.
Thanks for your comment. "Replicates" line is the header line and there are
two treatments in this case.
Probe id Treat1 Treat1 Treat1 treat1 Treat2 treat2 treat2
AFFX-BioB-5_at P P P P P P P
AFFX-BioB-M_at P P M P P M P
AFFX-BioB-3_at P M P A A P P
AFFX-BioC-5_at P P A M P A M
AFFX-BioC-3_at M M P A P P M
The output should be as follow without the process of calculation
Probe id Treat1 Treat2
AffX-BioB-5_at (2p +M)/4 =2 (2*3+0)/3=2
FFX-BioB-M_at (2*3+0)/4 =1.7 (2*3+0)/3=2
AFFX-BioB-3_at (2*2+0)/4 =1 (2*2+0)/3=1.3
AFFX-BioC-5_at (2*2+1)/4 =1.25 (2*1+1)/3=1
AFFX-BioC-3_at (2*1+1)/4 = 0.75 (2*2+1)/3=1.7
The denominator is always the # of replicates in each treatment.
Thanks,
Aiguo
-----Original Message-----
From: Zeus Odin [mailto:[Email Removed]]
Sent: Thursday, November 11, 2004 8:08 AM
To: [Email Removed]
Subject: Re: Why doesn't this work?
"Aiguo Li" <[Email Removed]> wrote in message...
Hello.
QUOTE |
I have the following dataset and want to calculate a P/A ratio for each replicates in the dataset. In this case, treatment 1 has 4 replicats and treatment2 has 3 replicates. The P/A = [((#of P)*2) + (# of M)]/# of replicates. The output should be two columns of P/A ratios for two treatments.
|
Your explanation doesn't make much sense to me. Maybe it's just me.
;-)
Is the line starting with "Replicates" a header row? I gleaned from your
code that
P/A = (2p + m)/a
where p, m, and a equal the number of P's, M's, and A's respectively on a
row. If this is true, what is to be done when a row is missing A, M, or P?
Of course, if A is missing then the equation is undefined because you have
zero in the denominator. You also state that the output should be two
columns, yet in your code you print $a, $m, and $p but nothing else.
It would be helpful if you took one record from below then manually compute
the two columns you want printed.
QUOTE |
I have made this far with the following code, but have not been able to make the code work yet. Could anybody shed some light on it?
Thanks,
AG
#!usr/bin/perl -w
use strict; use warnings;
my @split; my @replicate = ( 5, 3); my @ratio; my $p=0; my $m=0; my $a=0; my $rep=0; my $item; my $ratio;
open (FILE, "<C:/replicate.txt") or die "Can't open file: $!";
while( <FILE> ) { #print; chomp; @split = split (/t/, $_); push (@split, $_); #print "$_ n"; foreach $rep (@replicate) { for(my $i=1; $i<=$rep; $i++) { push (@split, $_); SWITCH: if ($_ =~ "P") {$p++; last SWITCH;} if ($_ =~ "M") {$m++; last SWITCH;} if ($_ =~ "A") {$a++; last SWITCH;} } print $p, $m, $a; @ratio = (($p*2)+$m)/$rep;
} }
close FILE;
|
--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]
<http://learn.perl.org/> <http://learn.perl.org/first-response>
Bob Showalter
Nov 11 2004, 07:36 PM
Ron Smith wrote:
QUOTE |
I'm trying to rename some files from the command line but nothing gets changed. I think I'm leaving out something; maybe '$_'. Or, I have incorrect syntax. I don't get any error message either. I took a look at 'man rename', but it doesn't show an example of a loop. I'm using the following on the command-line:
perl -e 'for (`ls -1`) { rename filename, newfilename if /w+$/}'
Can anyone show me the error of my ways?
|
What are you trying to do here? You're renaming a file called "filename" to
"newfilename" repeatedly.
'filename' and 'newfilename' are so-called 'barewords' here, and are treated
as strings in this context.
Perl has built-in globbing, so shelling to ls is not necessary.
Here's an article discussing the "classic" perl rename script. Why not start
with that?
http://www.evolt.org/article/Renaming_File...th_Perl/17/351/
Zeus Odin
Nov 12 2004, 05:07 AM
"Aiguo Li" <[Email Removed]> wrote in message ...
QUOTE |
Probe id Treat1 Treat2 AffX-BioB-5_at (2p +M)/4 =2 (2*3+0)/3=2 FFX-BioB-M_at (2*3+0)/4 =1.7 (2*3+0)/3=2 AFFX-BioB-3_at (2*2+0)/4 =1 (2*2+0)/3=1.3 AFFX-BioC-5_at (2*2+1)/4 =1.25 (2*1+1)/3=1 AFFX-BioC-3_at (2*1+1)/4 = 0.75 (2*2+1)/3=1.7
The denominator is always the # of replicates in each treatment.
|
Excellent. This is *much* clearer. The following appears to do what you
want. See comments about your code below.
---------------
#!/usr/bin/perl
use warnings;
use strict;
while (<DATA>) {
next unless /^A/;
my @data = split;
print join("t", $data[0], PA(@data[1..4]), PA(@data[5..7])), "n";
}
sub PA {
my @treat = @_;
my $m = count('M', @treat);
my $p = count('P', @treat);
return (2*$p + $m) / @treat;
}
sub count {
my $search = shift;
return scalar grep { $_ eq $search } @_;
}
__DATA__
Replicates 1 1 1 1 2 2 2
AFFX-BioB-5_at P P P P P P P
AFFX-BioB-M_at P P P P P P P
[snip]
---------------
QUOTE |
#!usr/bin/perl -w
use strict; use warnings;
|
You don't need both -w and use warnings. I read that "use warnings;" is
slightly preferred.
QUOTE |
my @split; my @replicate = ( 5, 3); my @ratio; my $p=0; my $m=0; my $a=0; my $rep=0; my $item; my $ratio;
|
There are way too many variables here. As a general rule you want to declare
the variable right before it's used. You want it in the smallest scope
possible so that you avoid having orphaned variables (you declared it but
forgot to use it). Do not declare $a; it has special meaning. See
"perldoc -f sort".
QUOTE |
open (FILE, "<C:/replicate.txt") or die "Can't open file: $!";
while( <FILE> ) { #print; chomp; @split = split (/t/, $_);
|
You are splitting on t. The data I received were delimited by spaces.
First you split and store the results in @split. You then add the entire
record to @split also. Is this really necessary?
QUOTE |
#print "$_ n"; foreach $rep (@replicate)
|
@replicate contains 5 and 3. If your code worked, shouldn't it contained 3
and 4? Doesn't this denote "the # of replicates in each treatment."
QUOTE |
{ for(my $i=1; $i<=$rep; $i++) { push (@split, $_); SWITCH: if ($_ =~ "P") {$p++; last SWITCH;} if ($_ =~ "M") {$m++; last SWITCH;} if ($_ =~ "A") {$a++; last SWITCH;}
|
Shouldn't this be next instead of last?
QUOTE |
} print $p, $m, $a; @ratio = (($p*2)+$m)/$rep;
|
You print these values but never print the result of the equation. You are
also setting an array equal to the result of the equation. You should print
the results of the equation or store it in a *scalar* not an array.
I would not solve this problem as you attempted here. Please see above.
Good luck,
ZO
Zeus Odin
Nov 13 2004, 03:08 PM
QUOTE |
Good morning, Zeus.
|
Good morning.
QUOTE |
Your codes is so neat and clean. I appreciate your help.
|
Why thank you. Everyone loves compliments.
:-)
QUOTE |
I have one question to you though.
|
You are more than welcome to cc me via email. However, please post to
perl.beginners in case I am away from my email and can't answer your query
in a reasonable timeframe.
QUOTE |
In the sub routine count, you used shift function. Does the shift function go through all the elements in a array?
|
Any time you don't understand a Perl function, look it up via perldoc. You
should NEVER ask a question about built-in functions without reading about
them first, ala:
$ perldoc -f shift
You should probably read
$ perldoc perldoc
also.
Therefore, the shift() in the sub:
sub count {
my $search = shift;
return scalar grep { $_ eq $search } @_;
}
Removes the first element of an array and stores it in $search. Because I
did not specify which array, the default array for subs is @_. If I had been
outside of a subroutine, the default array is @ARGV.
The first call to count is
my $m = count('M', @treat);
where @treat = ('P', 'P', 'P', 'P'). Because arguments are flattened by Perl
into one array the actual call that gets executed is:
my $m = count('M', 'P', 'P', 'P', 'P');
When the code enters the subroutine, @_ is aliased to ('M', 'P', 'P', 'P',
'P'). Therefore, the line
my $search = shift;
sets $search = 'M' and concurrently changes @_ to ('P', 'P', 'P', 'P'). Look
familiar? It should because this is Treatment 1 from the first record of
your data. The next line
return scalar grep { $_ eq $search } @_;
does what you initially asked and goes "through all the elements in a array"
via the grep function.
$ perldoc -f grep
Each time grep encounters M it returns that element. In this particular case
there are no M's and thus grep returns an empty list. The "return scalar"
says interpret the expression in scalar context. Since we have an empty
list, this evaluates to 0 (zero). return says go back to the calling routine
and take back the result to the right (0). Yep, you guessed it:
$ perldoc perlsub
$ perldoc -f scalar
$ perldoc -f return
perldoc is your FRIEND!
QUOTE |
If the data starts with a 'A' instead of 'P' or 'M', the number of 'P' or 'M' in that line will be counted or not?
|
This should now be clear: The first arugment to count() is the search
string. count() then searches for the search string in the rest of the
arugments. If the search string is found, count() returns the number of
occurrences, zero otherwise.
If you are a true Perl beginner, read an intro book first. I hear that
_Learning Perl_ by Randal L. Schwartz and Tom Phoenix is excellent.
http://www.bestwebbuys.com/Learning_Perl-I...l?isrc=b-search.
You should get the two Perl bibles: _Programming Perl 3rd Ed_ by Larry Wall
and _Perl Cookbook_ by by Tom Christiansen and Nathan Torkington.
QUOTE |
I hope that I made myself clear to you now.
|
Crystal clear. I hope I have done the same.
You're welcome. Good luck.
-ZO
QUOTE |
-----Original Message----- From: Zeus Odin [mailto:[Email Removed]] Sent: Friday, November 12, 2004 12:09 AM To: Li, Aiguo (NIH/NCI) Subject: Re: Why doesn't this work?
"Aiguo Li" <[Email Removed]> wrote in message ...
Probe id Treat1 Treat2 AffX-BioB-5_at (2p +M)/4 =2 (2*3+0)/3=2 FFX-BioB-M_at (2*3+0)/4 =1.7 (2*3+0)/3=2 AFFX-BioB-3_at (2*2+0)/4 =1 (2*2+0)/3=1.3 AFFX-BioC-5_at (2*2+1)/4 =1.25 (2*1+1)/3=1 AFFX-BioC-3_at (2*1+1)/4 = 0.75 (2*2+1)/3=1.7
The denominator is always the # of replicates in each treatment.
Excellent. This is *much* clearer. The following appears to do what you want. See comments about your code below.
--------------- #!/usr/bin/perl use warnings; use strict;
while (<DATA>) { next unless /^A/; my @data = split;
print join("t", $data[0], PA(@data[1..4]), PA(@data[5..7])), "n"; }
sub PA { my @treat = @_; my $m = count('M', @treat); my $p = count('P', @treat); return (2*$p + $m) / @treat; }
sub count { my $search = shift; return scalar grep { $_ eq $search } @_; }
__DATA__ Replicates 1 1 1 1 2 2 2 AFFX-BioB-5_at P P P P P P P AFFX-BioB-M_at P P P P P P P [snip] |
JupiterHost.Net
Nov 15 2004, 06:39 PM
Ian Harisay wrote:
Hello,
QUOTE |
Can anyone direct me to a Perl/MySQL shopping cart solution? I would
|
Click Cart Pro is excellent!
QUOTE |
like to use Authorize.net or Verisign as my gateway. Since this is off topic, please reply directly to me. I don't want to clutter the list with this subject.
|
I don't think its clutter to discuss excellent Perl programs via the list :)
We use Click Cart Pro for our ecommerce package:
See the "Ecommerce" option at:
http://www.jupiterhost.net/signup.plfor details and a link to more info and eventually theri site.
Interchange is very excellent also:
http://www.icdevgroup.org/HTH :)
Lee.M - JupiterHost.Net
Michael Kraus
Nov 17 2004, 06:52 AM
G'day...
Yeah, I should have used qw not qq, and after I sent it I thought "Why
didn't I just say keys %InheritableClassData instead.." :)
I'm trying to create a class that has data members which are the same
for all instances, including instances of derived classes, as well as
containing data members which exist in all instances, but values are
class dependent.
Considering that I've only more recently mastered the basics of
objects/classes in Perl - this is quite a daunting thing!
I've been reading through perltootc, but a lot of it goes straight over
the top of my head (or I only remember part of the concept Tom is
talking about).
I guess it means I just have to keep studying - although any help with
this task would be appreciated. :)
What I was trying to achieve with this:
--START--
: our %InheritableClassData = (
DBH => undef,
Q => undef,
Handler => undef,
);
foreach (qq(DBH Q Handler)) {
sub $_ {
shift;
$InheritableClassData{$_} = shift if @_;
return $InheritableClassData{$_};
}
}
---END---
Was really just an attempt at a shorthand version of:
--START--
: our %InheritableClassData = (
DBH => undef,
Q => undef,
Handler => undef,
);
sub DBH {
shift;
$InheritableClassData{DBH} = shift if @_;
return $InheritableClassData{DBH};
}
sub Q {
shift;
$InheritableClassData{Q} = shift if @_;
return $InheritableClassData{Q};
}
sub Handler {
shift;
$InheritableClassData{Handler} = shift if @_;
return $InheritableClassData{Handler};
}
---END---
Should I be using "my" or "our" here for the variables - these are the
variables I want present in all my derived classes and should be the
same for all.
Thanks heaps Charles, your help and assistance on this list is
appreciated by us all...
Regards,
Michael S. E. Kraus
Software Developer/Technical Support Specialist
Wild Technology Pty Ltd
________________________________
ABN 98 091 470 692
Level 4 Tiara, 306/9 Crystal Street, Waterloo NSW 2017, Australia
Telephone 1300-13-9453 | Facsimile 1300-88-9453
http://www.wildtechnology.net The information contained in this email message and any attachments may
be confidential information and may also be the subject of client legal
- legal professional privilege. If you are not the intended recipient,
any use, interference with, disclosure or copying of this material is
unauthorised and prohibited. This email and any attachments are also
subject to copyright. No part of them may be reproduced, adapted or
transmitted without the written permission of the copyright owner. If
you have received this email in error, please immediately advise the
sender by return email and delete the message from your system.
-----Original Message-----
From: Charles K. Clarkson [mailto:[Email Removed]]
Sent: Wednesday, 17 November 2004 5:30 PM
To: [Email Removed]
Subject: Spam:RE: Autmatic function creation
Michael Kraus <[Email Removed]> wrote:
: Just wondering if this code snippet will behave as expected,
: and if not then why not? :)
No, I don't think so. One error is in using the qq() operator
instead of the qw() operator. Even with that fix, perl throws syntax
errors.
: --START--
: our %InheritableClassData = (
: DBH => undef,
: Q => undef,
: Handler => undef,
: );
:
: foreach (qq(DBH Q Handler)) {
: sub $_ {
: shift;
: $InheritableClassData{$_} = shift if @_;
: return $InheritableClassData{$_};
: }
: }
We could test solutions by examining the symbol table.
When creating new functions (or methods in an object), perl adds
entries to the symbol table (%::). If we store the keys previous to
setting the functions, we can delete() them from the table keys
afterward and find if any new symbols were added.
use Data::Dumper 'Dumper';
.
.
.
# store current symbol table keys
my @prev_keys = keys %::;
foreach my $method ( keys %InheritableClassData ) {
no strict 'refs';
*$method = sub {
shift;
$InheritableClassData{$_} = shift if @_;
return $InheritableClassData{$_};
};
}
# store current symbol table
my %new_table = %::;
# delete old keys
delete @new_table{ @prev_keys };
print
"Added symbol table entriesn",
Dumper %new_table;
__END__
I get:
Added symbol table entries
$VAR1 = {
'Handler' => *::Handler,
'Q' => *::Q,
'DBH' => *::DBH
};
HTH,
Charles K. Clarkson
--
Mobile Homes Specialist
--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]
<http://learn.perl.org/> <http://learn.perl.org/first-response>
Michael Kraus
Nov 17 2004, 06:57 AM
Hi!
You mean something like:
--START--
our %InheritableClassData = (
DBH => undef,
Q => undef,
Handler => undef,
);
foreach (keys %InheritableClassData) {
$$_ = sub {
shift;
$InheritableClassData{$_} = shift if @_;
return $InheritableClassData{$_};
};
}
---END---
?
:)
Thanks heaps for your help!
Regards,
Michael S. E. Kraus
Software Developer/Technical Support Specialist
Wild Technology Pty Ltd
________________________________
ABN 98 091 470 692
Level 4 Tiara, 306/9 Crystal Street, Waterloo NSW 2017, Australia
Telephone 1300-13-9453 | Facsimile 1300-88-9453
http://www.wildtechnology.net The information contained in this email message and any attachments may
be confidential information and may also be the subject of client legal
- legal professional privilege. If you are not the intended recipient,
any use, interference with, disclosure or copying of this material is
unauthorised and prohibited. This email and any attachments are also
subject to copyright. No part of them may be reproduced, adapted or
transmitted without the written permission of the copyright owner. If
you have received this email in error, please immediately advise the
sender by return email and delete the message from your system.
-----Original Message-----
From: news [mailto:[Email Removed]] On Behalf Of K-sPecial
Sent: Wednesday, 17 November 2004 4:19 PM
To: [Email Removed]
Subject: Spam:Re: Autmatic function creation
Michael Kraus wrote:
QUOTE |
Just wondering if this code snippet will behave as expected, and if not then why not? :)
--START-- our %InheritableClassData = ( DBH => undef, Q => undef, Handler => undef, );
foreach (qq(DBH Q Handler)) { sub $_ { shift; $InheritableClassData{$_} = shift if @_; return $InheritableClassData{$_}; } } ---END---
|
Looks realy good here, I might use a closure through a typeglob to
assign the subroutine though.
--K-sPecial
--
To unsubscribe, e-mail: [Email Removed] For additional
commands, e-mail: [Email Removed] <http://learn.perl.org/>
<http://learn.perl.org/first-response>
Chris Devers
Nov 17 2004, 10:39 AM
Unless you're into beekeeping or dazzlingly wealthy tantric English rock
stars, you're looking for "strings" in your arrays, not "sting" :-)
On Wed, 17 Nov 2004, Bryan R Harris wrote:
QUOTE |
Mauro wrote: I have to check if $mystring is an elemen of @myarray or not. Which is the quickest way to do this?
That's a FAQ.
perldoc -q contained
Where can I find a list of the FAQs in perldoc? Seems most of my questions are FAQs too...
|
Try a simple `perldoc perlfaq` for starters.
Poking around on <http://perldoc.com/>, and their FAQ index at
<http://perldoc.com/perl5.8.4/pod/perlfaq.html>, might be a more
pleasant way to do this than just poking around on the command line.
--
Chris Devers
Charles K. Clarkson
Nov 17 2004, 02:48 PM
Michael Kraus <[Email Removed]> wrote:
: What I was trying to achieve with this:
:
: --START--
: our %InheritableClassData = (
: DBH => undef,
: Q => undef,
: Handler => undef,
: );
:
: foreach (qq(DBH Q Handler)) {
: sub $_ {
: shift;
: $InheritableClassData{$_} = shift if @_;
: return $InheritableClassData{$_};
: }
: }
: ---END---
:
: Was really just an attempt at a shorthand version of:
:
: --START--
: our %InheritableClassData = (
: DBH => undef,
: Q => undef,
: Handler => undef,
: );
:
: sub DBH {
: shift;
: $InheritableClassData{DBH} = shift if @_;
: return $InheritableClassData{DBH};
: }
:
: sub Q {
: shift;
: $InheritableClassData{Q} = shift if @_;
: return $InheritableClassData{Q};
: }
:
: sub Handler {
: shift;
: $InheritableClassData{Handler} = shift if @_;
: return $InheritableClassData{Handler};
: }
: ---END---
Perhaps you missed the solution I provided. It should provide
the methods you have above.
[snip]
: : foreach my $method ( keys %InheritableClassData ) {
: : no strict 'refs';
: : *$method = sub {
: : shift;
: : $InheritableClassData{$_} = shift if @_;
: : return $InheritableClassData{$_};
: : };
: : }
[snip]
: Should I be using "my" or "our" here for the variables - these
: are the variables I want present in all my derived classes and
: should be the same for all.
I don't know. I would play with each using multiple object
instances to be sure which is right. I am leaning more toward
'my', but I just don't know.
HTH,
Charles K. Clarkson
--
Mobile Homes Specialist
Dave Gray
Nov 17 2004, 04:00 PM
Charles K. Clarkson <[Email Removed]> wrote:
QUOTE |
[snip] : : foreach my $method ( keys %InheritableClassData ) { : : no strict 'refs'; : : *$method = sub { : : shift; : : $InheritableClassData{$_} = shift if @_; : : return $InheritableClassData{$_}; : : }; : : } [snip]
|
Perhaps it's just me, but I find the following approach to be clearer
for generating accessors:
==CODE==
#!/usr/bin/perl
use strict;
use warnings;
package test;
our %InheritableClassData;
for my $aa (qw/aa bb cc/) {
eval qq(
sub $aa {
shift;
$InheritableClassData{$aa} = shift if @_;
return $InheritableClassData{$aa};
}
);
}
package main;
print "$_n" for %{*test::};
=/CODE==
Michael Kraus <[Email Removed]> wrote:
QUOTE |
: Should I be using "my" or "our" here for the variables - these : are the variables I want present in all my derived classes and : should be the same for all.
|
I assume you're referring to things like %InheritableClassData... You
should be using "our" variables; "my" variables won't be visible from
outside the class in which they're declared.
Cheers,
Dave
Paul Johnson
Nov 17 2004, 09:44 PM
On Wed, Nov 17, 2004 at 11:00:17AM -0500, Dave Gray wrote:
QUOTE |
Charles K. Clarkson <[Email Removed]> wrote: [snip] : : foreach my $method ( keys %InheritableClassData ) { : : no strict 'refs'; : : *$method = sub { : : shift; : : $InheritableClassData{$_} = shift if @_; : : return $InheritableClassData{$_}; : : }; : : } [snip]
Perhaps it's just me, but I find the following approach to be clearer for generating accessors:
==CODE== #!/usr/bin/perl use strict; use warnings;
package test;
our %InheritableClassData; for my $aa (qw/aa bb cc/) { eval qq( sub $aa { shift; $InheritableClassData{$aa} = shift if @_; return $InheritableClassData{$aa}; } ); }
|
Downsides:
- all those ugly backslashes
- you don't see your errors or warnings until runtime
- and only then if you check $@
- and they'll look like "at (eval x) line y" which will leave you
wondering which eval is x and then which line is y
- you'll have similar problems when you come to use various tools such
as profilers or code coverage analysers
Upsides:
- you don't have to turn off strict refs
- you don't have to learn about globs
--
Paul Johnson - [Email Removed]
http://www.pjcj.net
Michael Kraus
Nov 17 2004, 10:50 PM
G'day...
QUOTE |
: Should I be using "my" or "our" here for the variables - these : are the variables I want present in all my derived classes and : should be the same for all.
I assume you're referring to things like %InheritableClassData... You should be using "our" variables; "my" variables won't be visible from outside the class in which they're declared.
|
Thanks... I think I may make them my variables though to make them a
little bit more private...
Regards,
Michael S. E. Kraus
Software Developer/Technical Support Specialist
Wild Technology Pty Ltd
[Email Removed]
_______________________________
ABN 98 091 470 692
Level 4 Tiara, 306/9 Crystal Street, Waterloo NSW 2017, Australia
Telephone 1300-13-9453 | Facsimile 1300-88-9453
http://www.wildtechnology.net The information contained in this email message and any attachments may
be confidential information and may also be the subject of client legal
- legal professional privilege. If you are not the intended recipient,
any use, interference with, disclosure or copying of this material is
unauthorised and prohibited. This email and any attachments are also
subject to copyright. No part of them may be reproduced, adapted or
transmitted without the written permission of the copyright owner. If
you have received this email in error, please immediately advise the
sender by return email and delete the message from your system.
Bob Showalter
Nov 19 2004, 01:34 PM
John Bruin wrote:
QUOTE |
I have a script that calculates difference between dates and it works well. However if the 2 dates straddle our daylight saving times (March, October) then the result is either plus or minus an hour compared to the expected result.
|
Are you subtracting "dates" or "local time stamps?" In the abstract, "dates"
have no reference to time zones.
Give some examples of what you're trying to do. What is the "expected
result"?
If you switch from daylight savings time at 2am on Sunday, October 31, then
the difference between the local times of noon on Saturday the 30th and noon
on Sunday the 31st is 25 hours, not 24 hours. If you're expecting it to be
24 hours, that's not correct.
QUOTE |
I am using date::parse (which uses Time::Local) to convert the date string to seconds and then localtime and strftime to convert back to a string.
|
What are you converting back to a string? The difference between the epoch
seconds?
Note that epoch seconds are always in GMT (UTC). In order for your parsing
routine to convert a string expressed in some local time to epoch seconds,
it needs to know the offset from the local time to GMT, which is a function
of the time zone.
Robert Freiberger
Nov 19 2004, 02:21 PM
What I would like to do is have two e-mail text boxes then have them enter their e-mail in both boxes, then once they click "submit" a check out run to see if the e-mail boxes are matching.
It's kinda of a problem with one e-mail text box because if someone enters in the wrong address I will have no way of contacting them back.
Thanks,
Rob
Chasecreek Systemhouse <[Email Removed]> wrote:
On Fri, 19 Nov 2004 10:24:14 -0800 (PST), robert freiberger
wrote:
QUOTE |
I have NSM's FormMail running on my site but I'm trying to figure out how to add a second e-mail text file and then match this to the first field, just to check that they entered the correct info.
I read over the readme file but didn't see anything related to this.
http://nms-cgi.sourceforge.net/scripts.shtml
|
What do you mean by correct?
Are they only allowed to enter a certain type or an exact match?
A long drawn out example:
http://backpan.cpan.org/authors/id/S/SN/SNEEX/infoRequest_v3--
WC -Sx- Jones
http://insecurity.org/--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]
Robert Freiberger
Bob Showalter
Nov 19 2004, 03:43 PM
Ramprasad A Padmanabhan wrote:
QUOTE |
I am using Net::SMTP to send mails to an SMTP server. If the server is running on a non std port how do I send mails to this port
|
Not documented, but inspection of the Net::SMTP code shows that:
$smtp = Net::SMTP->new($host, Port => 1234);
should do the trick (replace 1234 with the actual port)
HTH
Ramprasad A Padmanabhan
Nov 19 2004, 03:58 PM
On Fri, 2004-11-19 at 21:13, Bob Showalter wrote:
QUOTE |
Ramprasad A Padmanabhan wrote: I am using Net::SMTP to send mails to an SMTP server. If the server is running on a non std port how do I send mails to this port
Not documented, but inspection of the Net::SMTP code shows that:
$smtp = Net::SMTP->new($host, Port => 1234);
should do the trick (replace 1234 with the actual port)
HTH
|
Thanks a lot. I too gave it a shot just after posting. It worked.
Ram
Bob Showalter
Nov 19 2004, 10:11 PM
Lewick, Taylor wrote:
QUOTE |
Bob, thanks much for the help. That worked. One more question if you don't mind. Previously I had my script return the selected fields one on top of another, i.e. new table rows, but the code you sent me prints out all 15 fields in the same table row. I have tried playing with it but can't seem to get it to modify. Any ideas?
|
1. Keep the discussion on the list
2. Please don't top-post
3. If you want multiple rows, you need to pass an array ref to Tr(). Don't
use start_Tr and end_Tr like I did. You should be able to figure it out from
there. (Hint: how many Tr's do you need? What's inside each one?)
QUOTE |
-----Original Message----- From: Bob Showalter [mailto:[Email Removed]] Sent: Friday, November 19, 2004 2:57 PM To: Lewick, Taylor; [Email Removed] Subject: RE: question about doing it right in CGI
Lewick, Taylor wrote: Hi all, I have been using perl for sometime for CGI scripts, but have always used the print content-type:html version of doing things.
I would like to learn a better way with the CGI module, but when I read the docs I find it pretty easy to get confused as to whether I should use the object oriented method, or the functional method.
Either is fine IMO. The function method requires you to import the correct symbols, which can be a bit tricky.
Also, because my script is a cgi form that gets some of the select fields from a mysql database, I am not sure how to convert that over. I don't know how I would make the select field work the same.
I am not asking for someone to rewrite my project, merely provide me with some examples of how they would write the same code using the cgi module so I can figure this out a bit better...
On my form, I am querying a database for a list of names and loading them into a select box. But I found out people want to enter more than one name at a time, so I loop through 15 times, and they can select up to 15 names... They select a name, but I store the name's id, so it acts as a lookup field...
Here is how I do this now.. #Connect to database print "<table>n"; for (1..15) { print "<td nowrap>n"; $query_teams=("select id, name from teams"); $sth = $dbh->prepare($query_teams); $sth->execute(); $sth->bind_columns($id, $name); print "<select name='away_team$_'>"; #$_ traps which pass of the loop we are in i.e., 3rd pass, 4th pass, etc print "<option value='0'></option>n"; while($sth->fetch()) { print "<option value='$id'>$name</option>n"; } print "</select>n"; $sth->finish(); print "</td>n"; } #end for loop print "</table>n"; #disconnect from database
How would I start to convert this with the CGI module. My problems thus far are on a popup menu, how do I specify the field variable that I grab is the ID, while the displayed value is another, and how can I say the first value should be 0, in case they do not enter anything?
You're querying the database 15 times; I definitely wouldn't do that.
I ususally grab all the rows into an arrayref using something like this:
my $rows = $dbh->selectall_arrayref('select id, name from teams');
This handles all the DBI calls one one swoop.
For the CGI module's popup_menu, you need two things:
1) a list of values for the <option> elements, and 2) a hash of value => description pairs for the labels
Here's how to get the labels hash from the rows fetched above:
my %labels = ( 0 => '', map @$_, @$rows );
You can extract the value list from the hash keys:
my @values = sort { $a <=> $b } keys %labels;
Now you can generate the table by using CGI's routines like this (OO style):
print $q->start_table, $q->start_Tr, $q->td({ -nowrap => 'nowrap' }, [ map $q->popup_menu( -name => "away_team$_", -labels => %labels, -values => @values, -default => '0', ), 1 .. 15 ]), $q->end_Tr, $q->end_table;
CGI let's you use start_xxx and end_xxx methods to generate just a start or end tag.
If you pass an arrayref to a method like td(), CGI will generate multiple elements, one for each entry in the array. This lets us generate all 15 <td elements in one call. Look in the CGI docs under "THE DISTRIBUTIVE PROPERTY OF HTML SHORTCUTS"
The map() function generates a list of <select> objects.
HTH |
John Bruin
Nov 21 2004, 10:40 PM
QUOTE |
-----Original Message----- From: Bob Showalter [mailto:[Email Removed]] Sent: 20 November 2004 02:35 To: 'John Bruin'; 'Perl Beginners List' Subject: RE: Date calculations and daylight saving
John Bruin wrote: I have a script that calculates difference between dates and it works well. However if the 2 dates straddle our daylight saving times (March, October) then the result is either plus or minus an hour compared to the expected result.
Are you subtracting "dates" or "local time stamps?" In the abstract, "dates" have no reference to time zones.
Give some examples of what you're trying to do. What is the "expected result"?
If you switch from daylight savings time at 2am on Sunday, October 31, then the difference between the local times of noon on Saturday the 30th and noon on Sunday the 31st is 25 hours, not 24 hours. If you're expecting it to be 24 hours, that's not correct.
|
Yes this is exactly what I am try to do. I am working out how long jobs take
to complete and I need 1 day to equal 24 hrs and a week to equal 168 hrs
regardless of daylight saving change overs. We used to use a spreadsheet for
this calculation and that's what we're trying to duplicate. Technically
inaccurate yes but for our purposes it gives the expected result.
QUOTE |
I am using date::parse (which uses Time::Local) to convert the date string to seconds and then localtime and strftime to convert back to a string.
What are you converting back to a string? The difference between the epoch seconds?
|
Yes I convert the string to epoch seconds and calculate the difference
between the 2 dates. Then I add up how much time has been spent on that
particular job and how much time remains to meet the target completion time.
We get penalised if we pass this target completion time so the script
calculates the time and date each job should be finished based on the time
remaining.
QUOTE |
Note that epoch seconds are always in GMT (UTC). In order for your parsing routine to convert a string expressed in some local time to epoch seconds, it needs to know the offset from the local time to GMT, which is a function of the time zone.
|
Is what I am attempting to do feasible? Currently I am looking at Date::Calc
to see if I can do the calculations without offsetting for local time etc.
Thanks
John
Stephen Liu
Nov 21 2004, 11:11 PM
Hi John,
Please advise where can I find following modules
Date::Calc
date::parse
I can't find them with
# perl MCPAN -e 'Date::Calc'
Can't open perl script "MCPAN": No such file or
directory
# perl -MCPAN -e 'Date::Calc'
# perl -MCPAN -e 'date::parse'
# perl MCPAN -e 'date::parse'
Can't open perl script "MCPAN": No such file or
directory
# perl MCPAN -e 'Date::Parse'
Can't open perl script "MCPAN": No such file or
directory
# perl -MCPAN -e 'Date::Parse'
Thanks
B.R.
Stephen Liu
--- John Bruin <[Email Removed]> wrote:
QUOTE |
-----Original Message----- From: Bob Showalter [mailto:[Email Removed]] Sent: 20 November 2004 02:35 To: 'John Bruin'; 'Perl Beginners List' Subject: RE: Date calculations and daylight saving
John Bruin wrote: I have a script that calculates difference between dates and it works well. However if the 2 dates straddle our daylight saving times (March, October) then the result is either plus or minus an hour compared to the expected result.
Are you subtracting "dates" or "local time stamps?" In the abstract, "dates" have no reference to time zones.
Give some examples of what you're trying to do. What is the "expected result"?
If you switch from daylight savings time at 2am on Sunday, October 31, then the difference between the local times of noon on Saturday the 30th and noon on Sunday the 31st is 25 hours, not 24 hours. If you're expecting it to be 24 hours, that's not correct.
Yes this is exactly what I am try to do. I am working out how long jobs take to complete and I need 1 day to equal 24 hrs and a week to equal 168 hrs regardless of daylight saving change overs. We used to use a spreadsheet for this calculation and that's what we're trying to duplicate. Technically inaccurate yes but for our purposes it gives the expected result.
I am using date::parse (which uses Time::Local) to convert the date string to seconds and then localtime and strftime to convert back to a string.
What are you converting back to a string? The difference between the epoch seconds?
Yes I convert the string to epoch seconds and calculate the difference between the 2 dates. Then I add up how much time has been spent on that particular job and how much time remains to meet the target completion time. We get penalised if we pass this target completion time so the script calculates the time and date each job should be finished based on the time remaining.
Note that epoch seconds are always in GMT (UTC). In order for your parsing routine to convert a string expressed in some local time to epoch seconds, it needs to know the offset from the local time to GMT, which is a function of the time zone.
Is what I am attempting to do feasible? Currently I am looking at Date::Calc to see if I can do the calculations without offsetting for local time etc.
Thanks John |
Michael David
Nov 22 2004, 04:21 AM
perl -MCPAN -e 'install Date::Calc'
perl -MCPAN -e 'install Date::Parse'
(you forgot your install command)
OR
type cpan from the prompt then the 2 install packages
[prompt]$ cpan
cpan> install Date::Calc
cpan> install Date::Parse
----- Original Message -----
From: "Stephen Liu" <[Email Removed]>
To: "'Perl Beginners List'" <[Email Removed]>
Sent: Monday, November 22, 2004 3:11 PM
Subject: RE: Date calculations and daylight saving
QUOTE |
Hi John,
Please advise where can I find following modules
Date::Calc date::parse
I can't find them with
# perl MCPAN -e 'Date::Calc' Can't open perl script "MCPAN": No such file or directory # perl -MCPAN -e 'Date::Calc' # perl -MCPAN -e 'date::parse' # perl MCPAN -e 'date::parse' Can't open perl script "MCPAN": No such file or directory # perl MCPAN -e 'Date::Parse' Can't open perl script "MCPAN": No such file or directory # perl -MCPAN -e 'Date::Parse'
Thanks
B.R. Stephen Liu
--- John Bruin <[Email Removed]> wrote:
-----Original Message----- From: Bob Showalter [mailto:[Email Removed]] Sent: 20 November 2004 02:35 To: 'John Bruin'; 'Perl Beginners List' Subject: RE: Date calculations and daylight saving
John Bruin wrote: I have a script that calculates difference between dates and it works well. However if the 2 dates straddle our daylight saving times (March, October) then the result is either plus or minus an hour compared to the expected result.
Are you subtracting "dates" or "local time stamps?" In the abstract, "dates" have no reference to time zones.
Give some examples of what you're trying to do. What is the "expected result"?
If you switch from daylight savings time at 2am on Sunday, October 31, then the difference between the local times of noon on Saturday the 30th and noon on Sunday the 31st is 25 hours, not 24 hours. If you're expecting it to be 24 hours, that's not correct.
Yes this is exactly what I am try to do. I am working out how long jobs take to complete and I need 1 day to equal 24 hrs and a week to equal 168 hrs regardless of daylight saving change overs. We used to use a spreadsheet for this calculation and that's what we're trying to duplicate. Technically inaccurate yes but for our purposes it gives the expected result.
I am using date::parse (which uses Time::Local) to convert the date string to seconds and then localtime and strftime to convert back to a string.
What are you converting back to a string? The difference between the epoch seconds?
Yes I convert the string to epoch seconds and calculate the difference between the 2 dates. Then I add up how much time has been spent on that particular job and how much time remains to meet the target completion time. We get penalised if we pass this target completion time so the script calculates the time and date each job should be finished based on the time remaining.
Note that epoch seconds are always in GMT (UTC). In order for your parsing routine to convert a string expressed in some local time to epoch seconds, it needs to know the offset from the local time to GMT, which is a function of the time zone.
Is what I am attempting to do feasible? Currently I am looking at Date::Calc to see if I can do the calculations without offsetting for local time etc.
Thanks John
-- To unsubscribe, e-mail: [Email Removed] For additional commands, e-mail: [Email Removed] <http://learn.perl.org/> <http://learn.perl.org/first-response
|
Laurent Coudeur
Nov 22 2004, 12:13 PM
should it not be
$t->waitfor("/ord\s*:\s*/");
Regards.
Laurent.
-----Original Message-----
From: Ramprasad A Padmanabhan [mailto:[Email Removed]]
Sent: 22 November 2004 12:02
To: perl beginners
Subject: False warning by warnings.pm
I am using Net::Telnet in one of my perl scripts. Problem is every
time it runs with use warnings It prints out warnings like
Unrecognized escape s passed through at ....
Where that line is
$t->waitfor("/ords*:s*/");
Which is perfectly OK ( I think )
Can someone tell how to get rid of this warning ?
Thanks
Ram
--
To unsubscribe, e-mail: [Email Removed] For additional
commands, e-mail: [Email Removed] <http://learn.perl.org/>
<http://learn.perl.org/first-response>
Bob Showalter
Nov 22 2004, 02:22 PM
John Bruin wrote:
QUOTE |
... Yes this is exactly what I am try to do. I am working out how long jobs take to complete and I need 1 day to equal 24 hrs and a week to equal 168 hrs regardless of daylight saving change overs. We used to use a spreadsheet for this calculation and that's what we're trying to duplicate. Technically inaccurate yes but for our purposes it gives the expected result.
|
Let's see some data and the code that's not getting you the results you're
after. I still can't figure out what you're trying to do...
Chris Devers
Nov 22 2004, 03:02 PM
On Mon, 22 Nov 2004, FlashMX wrote:
QUOTE |
I need to open an external file, search for a hook like "start here" insert a line of code then keep searching until I find another hook called "end" then insert another line of code.
Keep ripping the file by searching for "start"..."end" insterting the start code and end code until the end of file is found. Then write the file out with the changes.
Can this be done?
|
Yes.
Write a program.
I bet Perl can do it!
Give it a try and let us know how it works out for you.
If you're looking for someone to write it for you, I'm sure some of the
people on this list would be willing to write it for a reasonable fee.
If you're trying to save some money, maybe you should try writing it by
yourself before turning to others for help.
--
Chris Devers
Peter Scott
Nov 22 2004, 03:14 PM
In article <[Email Removed]>,
[Email Removed] (John Bruin) writes:
QUOTE |
From: Bob Showalter [mailto:[Email Removed]] If you switch from daylight savings time at 2am on Sunday, October 31, then the difference between the local times of noon on Saturday the 30th and noon on Sunday the 31st is 25 hours, not 24 hours. If you're expecting it to be 24 hours, that's not correct.
Yes this is exactly what I am try to do. I am working out how long jobs take to complete and I need 1 day to equal 24 hrs and a week to equal 168 hrs regardless of daylight saving change overs. We used to use a spreadsheet for this calculation and that's what we're trying to duplicate. Technically inaccurate yes but for our purposes it gives the expected result.
|
Okay, well then you can either lie about whether you're in a daylight
saving time zone:
% perl -MDate::Parse -le 'print str2time("Sun Oct 31 01:00:00 PST 2004")
- str2time("Sat Oct 30 23:00:00 PST 2004")'
7200
vs. what you don't want:
% perl -MDate::Parse -le 'print str2time("Sun Oct 31 01:00:00 PST 2004")
- str2time("Sat Oct 30 23:00:00 PDT 2004")'
10800
Or you can just make the timezone the never-changing GMT:
% perl -MDate::Parse -le 'print str2time("Sun Oct 31 01:00:00 GMT 2004")
- str2time("Sat Oct 30 23:00:00 GMT 2004")'
7200
--
Peter Scott
http://www.perldebugged.com/*** NEW ***
http://www.perlmedic.com/
FlashMX
Nov 22 2004, 08:06 PM
A fee? Anyone take an apple?
On Mon, 22 Nov 2004 15:02:38 -0500 (EST), Chris Devers wrote:
QUOTE |
On Mon, 22 Nov 2004, FlashMX wrote:
I need to open an external file, search for a hook like "start here" insert a line of code then keep searching until I find another hook called "end" then insert another line of code.
Keep ripping the file by searching for "start"..."end" insterting the start code and end code until the end of file is found. Then write the file out with the changes.
Can this be done?
Yes.
If so, how?
Write a program.
I bet Perl can do it!
Give it a try and let us know how it works out for you.
If you're looking for someone to write it for you, I'm sure some of the people on this list would be willing to write it for a reasonable fee. If you're trying to save some money, maybe you should try writing it by yourself before turning to others for help.
-- Chris Devers
-- To unsubscribe, e-mail: [Email Removed] For additional commands, e-mail: [Email Removed] <http://learn.perl.org/> <http://learn.perl.org/first-response
|
Octavian Rasnita
Nov 22 2004, 08:13 PM
Oh yes, me me!!!
Here is the program:
print "This program should do what you want';
That was the program. I hope it will work. If it won't or if it will give an
error, sorry.
The apple was pretty good.
:-)
Teddy
----- Original Message -----
From: "FlashMX" <[Email Removed]>
To: "Perl Beginners List" <[Email Removed]>
Sent: Monday, November 22, 2004 10:06 PM
Subject: Re: Using Perls built in GREP
A fee? Anyone take an apple?
On Mon, 22 Nov 2004 15:02:38 -0500 (EST), Chris Devers wrote:
QUOTE |
On Mon, 22 Nov 2004, FlashMX wrote:
I need to open an external file, search for a hook like "start here" insert a line of code then keep searching until I find another hook called "end" then insert another line of code.
Keep ripping the file by searching for "start"..."end" insterting the start code and end code until the end of file is found. Then write the file out with the changes.
Can this be done?
Yes.
If so, how?
Write a program.
I bet Perl can do it!
Give it a try and let us know how it works out for you.
If you're looking for someone to write it for you, I'm sure some of the people on this list would be willing to write it for a reasonable fee. If you're trying to save some money, maybe you should try writing it by yourself before turning to others for help.
-- Chris Devers
-- To unsubscribe, e-mail: [Email Removed] For additional commands, e-mail: [Email Removed] <http://learn.perl.org/> <http://learn.perl.org/first-response
|
--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]
<http://learn.perl.org/> <http://learn.perl.org/first-response>
John Bruin
Nov 23 2004, 12:09 AM
Peter - thanks very much. I'll use the GMT trick.
John
QUOTE |
-----Original Message----- From: Peter Scott [mailto:[Email Removed]] Sent: 23 November 2004 04:14 To: [Email Removed] Subject: RE: Date calculations and daylight saving
In article <[Email Removed]>, [Email Removed] (John Bruin) writes: From: Bob Showalter [mailto:[Email Removed]] If you switch from daylight savings time at 2am on Sunday, October 31, then the difference between the local times of noon on Saturday the 30th and noon on Sunday the 31st is 25 hours, not 24 hours. If you're expecting it to be 24 hours, that's not correct.
Yes this is exactly what I am try to do. I am working out how long jobs take to complete and I need 1 day to equal 24 hrs and a week to equal 168 hrs regardless of daylight saving change overs. We used to use a spreadsheet for this calculation and that's what we're trying to duplicate. Technically inaccurate yes but for our purposes it gives the expected result.
Okay, well then you can either lie about whether you're in a daylight saving time zone:
% perl -MDate::Parse -le 'print str2time("Sun Oct 31 01:00:00 PST 2004") - str2time("Sat Oct 30 23:00:00 PST 2004")' 7200
vs. what you don't want:
% perl -MDate::Parse -le 'print str2time("Sun Oct 31 01:00:00 PST 2004") - str2time("Sat Oct 30 23:00:00 PDT 2004")' 10800
Or you can just make the timezone the never-changing GMT:
% perl -MDate::Parse -le 'print str2time("Sun Oct 31 01:00:00 GMT 2004") - str2time("Sat Oct 30 23:00:00 GMT 2004")' 7200
-- Peter Scott http://www.perldebugged.com/ *** NEW *** http://www.perlmedic.com/
-- To unsubscribe, e-mail: [Email Removed] For additional commands, e-mail: [Email Removed] <http://learn.perl.org/> <http://learn.perl.org/first-response
|
Chris Devers
Nov 23 2004, 09:44 AM
On Tue, 23 Nov 2004, FlashMX wrote:
QUOTE |
I'm trying to do this script on my own as suggested by someone in this group.
|
Glad to hear it :-)
QUOTE |
I'm getting confused on the login.
|
I don't see where the program or the problem description involves
logging in to anything -- is that really what you meant, or do you mean
some other concept?
QUOTE |
I need to open the orginal file (which I've done) and then do a grep to search and then replace some text but I need to output the results to the same file (can this be done?).
|
Well, one easy way to do that is to use a temp file:
* open original file
* find what you want in the file
* output the results to the temp file
* move the temp file over the original file
There are other ways to go about this, but this framework is one of the
easier approaches to the problem.
You could also iterate over the file, deleting each line that doesn't
match the pattern you want, but this would be a little more complicated
to write (not bad, mind you, just a little less straightforward) and I'm
not sure that it would be any better than the steps outlined above.
--
Chris Devers
FlashMX
Nov 23 2004, 02:49 PM
On Tue, 23 Nov 2004 09:44:00 -0500 (EST), Chris Devers wrote:
QUOTE |
On Tue, 23 Nov 2004, FlashMX wrote:
I'm trying to do this script on my own as suggested by someone in this group.
Glad to hear it :-)
I'm getting confused on the login.
I don't see where the program or the problem description involves logging in to anything -- is that really what you meant, or do you mean some other concept
|
Doh...I meant to type "logic"
QUOTE |
I need to open the orginal file (which I've done) and then do a grep to search and then replace some text but I need to output the results to the same file (can this be done?).
Well, one easy way to do that is to use a temp file:
* open original file * find what you want in the file * output the results to the temp file * move the temp file over the original file
There are other ways to go about this, but this framework is one of the easier approaches to the problem.
You could also iterate over the file, deleting each line that doesn't match the pattern you want, but this would be a little more complicated to write (not bad, mind you, just a little less straightforward) and I'm not sure that it would be any better than the steps outlined above.
|
I would still need to keep the original file intact. Bascially just reading in a large file. Using GREP to search for a match like "0000" then replace that with "0000 1111 and then search for
2222 and then replace that with 2222 3333 and then start the search over again at 0000...and so on at the same time writing the results to (I guess) a temp file and then rename the temp
file to the original when completed.
Being new I just want to make sure all my steps are correct.
FlashMX
Nov 23 2004, 07:49 PM
Hi,
The code below opens a file and writes the contents to a temporary file. I need to do a search and replace of certain matches in the files and I thought I might be able to use regular
expressions.
Being new to perl and now trying expressions has almost put me over the edge.
When I run the below code I get this error:
Global symbol output requires explicit package name at filename.pl line 18....
Im not sure whats wrong by the error.
#!/usr/local/bin/perl
use strict ;
my $ofile = "file.out";
my $ifile = "file.in";
open(INPUT, $ifile) or die "Can't open input file: $ifile ($!)" ;
my @match_lines = <INPUT>;
close ( INPUT );
open( OUTPUT, "> $ofile" );
$output = ~ s/AAA*?BBBt/AAA 111 *?222 BBB/g;
print OUTPUT @match_lines;
close ( OUTPUT );
#rename($ofile, $ifile) ;
Michael Kraus
Nov 24 2004, 02:52 AM
You're right... An attempt to execute `$self->{DBFields}->{$field} = ""`
results in the error "Not a HASH reference at line x"
Regards,
Michael S. E. Kraus
Software Developer
Wild Technology Pty Ltd
_______________________________
ABN 98 091 470 692
Level 4 Tiara, 306/9 Crystal Street, Waterloo NSW 2017, Australia
Telephone 1300-13-9453 | Facsimile 1300-88-9453
http://www.wildtechnology.net The information contained in this email message and any attachments may
be confidential information and may also be the subject of client legal
- legal professional privilege. If you are not the intended recipient,
any use, interference with, disclosure or copying of this material is
unauthorised and prohibited. This email and any attachments are also
subject to copyright. No part of them may be reproduced, adapted or
transmitted without the written permission of the copyright owner. If
you have received this email in error, please immediately advise the
sender by return email and delete the message from your system.
QUOTE |
-----Original Message----- From: Michael Kraus [mailto:[Email Removed]] Sent: Wednesday, 24 November 2004 1:45 PM To: Gunnar Hjalmarsson; [Email Removed] Subject: Spam:RE: Spam:Re: How do I create an empty anonymous hash with a hash declaration?
G'day...
When using our %Super_DB_Object = ( TableName => "", DBFields => {}, NotNull => [], );
Make sure you remove:
my $field_hash = {}; $self->{DBFields} = $field_hash;
And try accessing the hash directly.
If you don't see what I mean then, let me know - as a complete code list spans three files. :)
Regards,
Michael S. E. Kraus Software Developer Wild Technology Pty Ltd _______________________________ ABN 98 091 470 692 Level 4 Tiara, 306/9 Crystal Street, Waterloo NSW 2017, Australia Telephone 1300-13-9453 | Facsimile 1300-88-9453 http://www.wildtechnology.net
The information contained in this email message and any attachments may be confidential information and may also be the subject of client legal - legal professional privilege. If you are not the intended recipient, any use, interference with, disclosure or copying of this material is unauthorised and prohibited. This email and any attachments are also subject to copyright. No part of them may be reproduced, adapted or transmitted without the written permission of the copyright owner. If you have received this email in error, please immediately advise the sender by return email and delete the message from your system.
-----Original Message----- From: Gunnar Hjalmarsson [mailto:[Email Removed]] Sent: Wednesday, 24 November 2004 1:20 PM To: [Email Removed] Subject: Spam:Re: How do I create an empty anonymous hash with a hash declaration?
Michael Kraus wrote:
our %Super_DB_Object = ( TableName => "", DBFields => {}, NotNull => [], ); ---CUT---
However, when I do that, I get the error: "Odd number of elements in hash"
That code does not generate the warning message you mention. Please copy and post a short but *complete* program that illustrates the problem.
-- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl
-- To unsubscribe, e-mail: [Email Removed] For additional commands, e-mail: [Email Removed] <http://learn.perl.org/ <http://learn.perl.org/first-response
-- To unsubscribe, e-mail: [Email Removed] For additional commands, e-mail: [Email Removed] <http://learn.perl.org/> <http://learn.perl.org/first-response
|
Prasanna Kothari
Nov 24 2004, 04:47 AM
Hi,
Replace
$output = ~ s/AAA*?BBBt/AAA 111 *?222 BBB/g;
with
my $output =~ s/AAA*?BBBt/AAA 111 *?222 BBB/g;
You can use "perl -c <filename>" which will show you such type of errors.
After opening the output file, it's better to check if the file is
opened successfully(as done in the case of INPUT).
I think there's something wrong with the logic.
The INPUT file is opened, all it's contents are in the array
@match_lines, and then after doing a pattern match, you are just
printing the values to the output file.
Your script has not replaced anything.
Use grep function to replace all the contents of an array and write the
array back to the output file.
--Prasanna
FlashMX wrote:
QUOTE |
Hi,
The code below opens a file and writes the contents to a temporary file. I need to do a search and replace of certain matches in the files and I thought I might be able to use regular expressions. Being new to perl and now trying expressions has almost put me over the edge.
When I run the below code I get this error:
Global symbol output requires explicit package name at filename.pl line 18....
Im not sure whats wrong by the error.
#!/usr/local/bin/perl use strict ;
my $ofile = "file.out"; my $ifile = "file.in";
open(INPUT, $ifile) or die "Can't open input file: $ifile ($!)" ; my @match_lines = <INPUT>; close ( INPUT );
open( OUTPUT, "> $ofile" );
$output = ~ s/AAA*?BBBt/AAA 111 *?222 BBB/g;
print OUTPUT @match_lines; close ( OUTPUT );
#rename($ofile, $ifile) ;
|
Chris Devers
Nov 24 2004, 08:41 AM
On Wed, 24 Nov 2004, Todd Lewis wrote:
QUOTE |
If your [unspecified object, possibly "script"] [is] writing something[comma] I think you can output your die statement into a "log file" using print [logfile] "Whatever message you wantn". You can also at certain points in your program output information on the status of your program. It helps in debugging your program.
If it is a long[ ]running process you can always open the logfile and see where you are.
|
Right, but none of this explains where "log()" came from.
It may be a method provided by some module he's using; it may be legacy
code that he's maintaining; it may be nothing at all. We don't know.
But yeah, if starting from scratch, the outline above will help.
--
Chris Devers
FlashMX
Nov 24 2004, 12:00 PM
Could you give an example of using grep on a array to do a replace?
On Wed, 24 Nov 2004 10:05:39 +0530, Prasanna Kothari wrote:
QUOTE |
Hi, Replace $output = ~ s/AAA*?BBBt/AAA 111 *?222 BBB/g; with my $output =~ s/AAA*?BBBt/AAA 111 *?222 BBB/g;
You can use "perl -c <filename>" which will show you such type of errors.
After opening the output file, it's better to check if the file is opened successfully(as done in the case of INPUT).
I think there's something wrong with the logic. The INPUT file is opened, all it's contents are in the array @match_lines, and then after doing a pattern match, you are just printing the values to the output file. Your script has not replaced anything. Use grep function to replace all the contents of an array and write the array back to the output file.
--Prasanna FlashMX wrote:
Hi,
The code below opens a file and writes the contents to a temporary file. I need to do a search and replace of certain matches in the files and I thought I might be able to use regular expressions. Being new to perl and now trying expressions has almost put me over the edge.
When I run the below code I get this error:
Global symbol output requires explicit package name at filename.pl line 18....
Im not sure whats wrong by the error.
#!/usr/local/bin/perl use strict ;
my $ofile = "file.out"; my $ifile = "file.in";
open(INPUT, $ifile) or die "Can't open input file: $ifile ($!)" ; my @match_lines = <INPUT>; close ( INPUT );
open( OUTPUT, "> $ofile" );
$output = ~ s/AAA*?BBBt/AAA 111 *?222 BBB/g;
print OUTPUT @match_lines; close ( OUTPUT );
#rename($ofile, $ifile) ;
-- To unsubscribe, e-mail: [Email Removed] For additional commands, e-mail: [Email Removed] <http://learn.perl.org/> <http://learn.perl.org/first-response
|
FlashMX
Nov 24 2004, 12:10 PM
To be able to do a grep on a file via a perl script do you have to read the whole file in before performing the search and replace? I've been hearing that reading the whole file in takes up
memory and if multiple users are running the script then you better have alot of swap and memory.
Is this correct?
If this is the case how else could I do a grep to do a search and replace without using all the resources?
On Wed, 24 Nov 2004 07:00:24 -0500, FlashMX wrote:
QUOTE |
Could you give an example of using grep on a array to do a replace?
On Wed, 24 Nov 2004 10:05:39 +0530, Prasanna Kothari wrote:
Hi, Replace $output = ~ s/AAA*?BBBt/AAA 111 *?222 BBB/g; with my $output =~ s/AAA*?BBBt/AAA 111 *?222 BBB/g;
You can use "perl -c <filename>" which will show you such type of errors.
After opening the output file, it's better to check if the file is opened successfully(as done in the case of INPUT).
I think there's something wrong with the logic. The INPUT file is opened, all it's contents are in the array @match_lines, and then after doing a pattern match, you are just printing the values to the output file. Your script has not replaced anything. Use grep function to replace all the contents of an array and write the array back to the output file.
--Prasanna FlashMX wrote:
Hi,
The code below opens a file and writes the contents to a temporary file. I need to do a search and replace of certain matches in the files and I thought I might be able to use regular expressions. Being new to perl and now trying expressions has almost put me over the edge.
When I run the below code I get this error:
Global symbol output requires explicit package name at filename..pl line 18....
Im not sure whats wrong by the error.
#!/usr/local/bin/perl use strict ;
my $ofile = "file.out"; my $ifile = "file.in";
open(INPUT, $ifile) or die "Can't open input file: $ifile ($!)" ; my @match_lines = <INPUT>; close ( INPUT );
open( OUTPUT, "> $ofile" );
$output = ~ s/AAA*?BBBt/AAA 111 *?222 BBB/g;
print OUTPUT @match_lines; close ( OUTPUT );
#rename($ofile, $ifile) ;
-- To unsubscribe, e-mail: [Email Removed] For additional commands, e-mail: [Email Removed] <http://learn.perl.org/> <http://learn.perl.org/first-response
-- To unsubscribe, e-mail: [Email Removed] For additional commands, e-mail: [Email Removed] <http://learn.perl.org/> <http://learn.perl.org/first-response
|
Chris Devers
Nov 24 2004, 12:29 PM
On Wed, 24 Nov 2004, FlashMX wrote:
QUOTE |
I'm trying to understand the logic. When you open a file each line is read in one at a time. At that point you can do whatever you want to that line. In my case a search and replace.
Can I do two search and replaces on the same line or would I have to open the file again for a second pass?
|
You answered your own question -- "you can do whatever you want to that
line".
while <> {
my $line = $_;
$line = sub_one( $line );
$line = sub_two( $line );
}
Etc.
--
Chris Devers
Michael S. E. Kraus
Nov 24 2004, 12:34 PM
G'day...
On Wed, 2004-11-24 at 23:10, FlashMX wrote:
QUOTE |
To be able to do a grep on a file via a perl script do you have to read the whole file in before performing the search and replace? I've been hearing that reading the whole file in takes up memory and if multiple users are running the script then you better have alot of swap and memory.
Is this correct?
|
Yes and No... You can read a whole file in and perform changes, and
then write out the differences to the same filename...
This may or may not take up much memory... a 23K file is only 23K after
all... it all depends on your averages...
QUOTE |
If this is the case how else could I do a grep to do a search and replace without using all the resources?
|
You can also read a file in a line at a time, perform the search and
replace on each line, and write the output to a new file... then at the
end replace the old file with the new one...
E.g.
open (INFILE, "< $filename");
open (OUTFILE, "> $filename.$$");
for my $line (<INFILE>) {
$line =~ s/old/new/gi;
print OUTFILE $line;
}
close(OUTFILE);
close(INFILE);
rename("$filename.$$","$filename");
Get yourself a copy of ORA's "Learning Perl" for starters...
HTH...
All the best...
-Mike
Michael S. E. Kraus
Nov 24 2004, 12:50 PM
G'day...
On Wed, 2004-11-24 at 23:00, FlashMX wrote:
QUOTE |
Could you give an example of using grep on a array to do a replace?
|
grep example:
if (grep(/bazza/i, @myarray)) {
print "Bazza's home!n";
}
OR
my @bazza_list = grep {/bazza/i} @myarray;
(Either form is fine)
However to do a replace, I'd be more likely to use something like map.
grep is a search function... map can work well as a replacement function (I think of map as map one set of values to another set of values...)
E.g.
my @new_array = map { s/old/new/gi } @old_array;
Really map just goes through your list, mapping each item to $_ and performs the given expression on them...
(Err.. I think the example above actually modifies the contents of @old_array ...)
See
http://www.raycosoft.com/rayco/support/perl_tutor.html for instructions and examples on these functions...
HTH...
All the best...
-Mike
Chris Devers
Nov 24 2004, 12:55 PM
On Wed, 24 Nov 2004, FlashMX wrote:
QUOTE |
Right...but my problem is I don't want the substitutions to happen on ALL the lines matched.
|
Fine then.
$line = sub_one( $line ) COND;
Where COND is any condition you specify, e.g.
$line = sub_one( $line ) if ( $line =~ /pattern one/ );
$line = sub_two( $line ) unless ( $line =~ /pattern two/ );
Of you can put the logic in the hypothetical subroutine:
sub sub_one {
return $_ unless ( $_ =~ /pattern one/ );
...
}
But I think putting the condition in the first way is clearer here.
--
Chris Devers
Bob Showalter
Nov 24 2004, 01:38 PM
Gunnar Hjalmarsson wrote:
QUOTE |
I don't know what log() is.
|
perldoc -f log
:~)
FlashMX
Nov 24 2004, 03:46 PM
Hi,
I'm trying to understand the logic. When you open a file each line is read in one at a time. At that point you can do whatever you want to that line. In my case a search and replace.
Can I do two search and replaces on the same line or would I have to open the file again for a second pass?
FlashMX
Nov 24 2004, 05:41 PM
Right...but my problem is I don't want the substitutions to happen on ALL the lines matched. Notice from the below input and output examples I do a grep to search for "0 AAA ".
I then do a substitution on "0 AAA " to "0 AAA BBB ". Then the first occurence of "" after the "0 AAA " substitution gets replaced with "111 " and ALL other "" gets ignored (no
substution on these) until the next "0 AAA " and so on...
I have also included by script below. The below script substitues the first match by using ?? in the GREP but not the next "" following next grep match on "0 AAA "
I'm starting to babble...
Here is the input file:
0101 0101 0101 0101 0101 0101 0101 0101 0101
0101 0101 0101 0101 0101 0101 0101 0101 0101
You want to find what. You want to find what? 0 0 0 AAA
0101 0101 0101 0101 0101 0101 0101 0101 0101
0101 0101 0101 0101 0101 0101 0101 0101 0101
0101 0101 0101 0101 0101 0101 0101 0101 0101
0101 0101 0101 0101 0101 0101 0101 0101 0101
0101 0101 0101 0101 0101 0101 0101 0101 0101
0101 0101 0101 0101 0101 0101 0101 0101 0101
0101 0101 0101 0101 0101 0101 0101 0101 0101
0101 0101 0101 0101 0101 0101 0101 0101 0101
You want to find what. You want to find what? 0 0 0 AAA
0101 0101 0101 0101 0101 0101 0101 0101 0101
0101 0101 0101 0101 0101 0101 0101 0101 0101
0101 0101 0101 0101 0101 0101 0101 0101 0101
0101 0101 0101 0101 0101 0101 0101 0101 0101
0101 0101 0101 0101 0101 0101 0101 0101 0101
0101 0101 0101 0101 0101 0101 0101 0101 0101
Here is what the output file should look like:
0101 0101 0101 0101 0101 0101 0101 0101 0101
0101 0101 0101 0101 0101 0101 0101 0101 0101
You want to find what. You want to find what? 0 0 0 AAA BBB
0101 0101 0101 0101 0101 0101 0101 0101 0101
0101 0101 0101 0101 0101 0101 0101 0101 0101
111
0101 0101 0101 0101 0101 0101 0101 0101 0101
0101 0101 0101 0101 0101 0101 0101 0101 0101
0101 0101 0101 0101 0101 0101 0101 0101 0101
0101 0101 0101 0101 0101 0101 0101 0101 0101
0101 0101 0101 0101 0101 0101 0101 0101 0101
0101 0101 0101 0101 0101 0101 0101 0101 0101
You want to find what. You want to find what? 0 0 0 AAA BBB
0101 0101 0101 0101 0101 0101 0101 0101 0101
0101 0101 0101 0101 0101 0101 0101 0101 0101
111
0101 0101 0101 0101 0101 0101 0101 0101 0101
0101 0101 0101 0101 0101 0101 0101 0101 0101
0101 0101 0101 0101 0101 0101 0101 0101 0101
0101 0101 0101 0101 0101 0101 0101 0101 0101
test.pl
=====
#!/usr/local/bin/perl
#use strict;
my $ifile = "file.in";
my $ofile = "file.out";
my $line;
open (INFILE, "< $ifile");
open (OUTFILE, "> $ofile");
foreach $line (<INFILE>) {
if (grep(/0 AAA /, $line)) {
$line =~ s/0 AAA/0 AAA BBB/g;
}
if (grep(??, $line)) {
$line =~ s/ /111 /g;
}
print OUTFILE $line;
}
close(OUTFILE);
close(INFILE);
#rename($ofile, $ifile);
On Wed, 24 Nov 2004 12:29:13 -0500 (EST), Chris Devers wrote:
QUOTE |
On Wed, 24 Nov 2004, FlashMX wrote:
I'm trying to understand the logic. When you open a file each line is read in one at a time. At that point you can do whatever you want to that line. In my case a search and replace.
Can I do two search and replaces on the same line or would I have to open the file again for a second pass?
You answered your own question -- "you can do whatever you want to that line".
while <> { my $line = $_; $line = sub_one( $line ); $line = sub_two( $line ); }
Etc.
-- Chris Devers |
Charles K. Clarkson wrote:
QUOTE |
From: Wagner, David --- Senior Programmer Analyst --- WGO <> wrote:
I have been working on thie script to take MVS JCl/Proc's and bring them together in a single output. I parsing out the DSN ( data file name ) and then attempting to determine if input, output or delete.
Here is the code ( quite large unforunately ).
But not large enough. I think you need to give a working sample which shows the problem you are having. The code you gave has at least one syntax error. Your example should be something we can run and duplicate the problem you are having. This means you'll need to supply some of the input data as well.
[snip] $MyWrkId++ if ( (! $MyHitDisp) or $MyNeedLRECL ) );
|
Sorry about that, but I cut and copied. Yes. A working copy would be the correct method, but it was going to be too large and it really bothered me that the code was not working as it should. So I made one change, I moved the data to $_ and for two of the regex's within the block, I removed $'MyWorka[$MyWrkId] =~' , so they would be going against $_ and everything worked as it should then. No longer was it failing on the regex, but working as it should.
What I had was an outer loop that I was reading from the array @WyWorka and moving to $_. I was then doing a number regex's looking for data. On this one, it had initially been just pulling the DSN and no more, but one of the developers I showed the data to asked if possible to determine if input, output, deleting and if output what is the size of the record. So I did the while loop using another index, but here is where it would fail. SO as I stated above, I moved my entry to $_ ( since next processing went again to the outer loop and $_ was not used again) and modified the other two regexs to go against. I ran a difference program and the only changes made and it now works. Why? I don't know, but for this one, I will leave it alone and go from there.
Again, thanks for taking the time to look.
QUOTE |
The line above has an extra ')' init.
HTH,
Charles K. Clarkson -- Mobile Homes Specialist
|
*******************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
*******************************************************