1.
$filename = 'foo.txt';
open(FH,$filename) or die couldn't open $filename - $!;
while ($line = FH){
print $line matches\n if ($line =~ /^USD /);
}
2.
while ($line=FH){
chomp $line;
next unless $line;
next if ($line =~ /^-+?$/);
next if ($line =~ /^=+?$/);
# only good
Me wrote:
Analysis of the code you attached.
$quote_date = substr($_,0,79);
The above line is pointless.
--- Agreed.
The next couple lines are great:
($year, $month, $mday, $hour, $minute, $second, $timezone) =
$quote_date = /^Rates as of (\d+).(\d+).(\d+)
($year, $month, $mday, $hour, $minute, $second, $timezone) =
/^Rates as of (\d+).(\d+).(\d+) (\d+):(\d+):(\d+) (\w+) (.*)$/;
The following code is pointless:
$year = $1;
$month = $2;
$mday = $3;
$hour = $4;
$minute = $5;
currency.csv contains using the code below. The date has been
adjusted from 2000-12-30 00:16:19 UTC to PST. The rest of the file is
still not being processed.
2000-12-29,16:16:19,PST
#!/usr/bin/perl
#
# cur2csv.pl
#
use strict;
use vars qw($started);
use vars qw($quote_date $cur_sym
printf OUTFILE %s\,%s\,%s\,%s\,%s\,%s\,%s\n,
$date, $time, $tz, $cur_sym, $cur_desc, $usd_unit, $units_usd;
close(INFILE);
close(OUTFILE);
print STDERR \n;
1;
You seem to be misunderstanding one particular
aspect of perl. Given the following:
while (INFILE) {
# do something
The second loop is executing. The TEST statement worked.
This will surely print out, which shows that the regex
didn't match. In other words:
($cur_sym, $cur_desc, $usd_unit, $units_usd) =
/^([A-Z]{3})( [A-Za-z])+\s+(\d+\.\d+)\s+(\d+\.\d+)\s*$/;
Doesn't match:
USD United
The second loop is executing. The TEST statement worked.
Ok.
The Currency part of the email has a fixed format that is never
deviated from:
1-3 $cur_sym
4 space
5-32 $cur_desc
33-35 (3) spaces
36-55 d8.d10 (.00)
56-58 (3) spaces
59-78 d8.d10 (.00)
Got a combination that sort of works. It returns all the required
fields but truncates any line where $usd_unit or $units_usd has more
than 1 digit before the decimal point. There can be as many as (8)
digits before and (10) digits after the decimal point in both cases.
Here's the regex I'm
Got a combination that sort of works. It returns all the required
fields but truncates any line where $usd_unit or $units_usd has more
than 1 digit before the decimal point. There can be as many as (8)
digits before and (10) digits after the decimal point in both cases.
Here's the regex
1. I want to read in a text file and match any line that begins with
three capital letters followed by a space. i.e. USD
How do you do that?
2. I need to ignore any blank lines, lines containing all ---, lines
containing all ===.
Again, how?
Thanks in advance,
Jack
1. I want to read in a text file and match any line that begins with
three capital letters followed by a space. i.e. USD
while () {
/^[A-Z]{3} / and dostuff; # $_ contains line
}
2. I need to ignore any blank lines, lines containing all ---, lines
containing all ===.
I forgot to explain.
1. I want to read in a text file and match any line that begins with
three capital letters followed by a space. i.e. USD
while () {
will read from the file(s) you specify on the command
line when you run your perl script, ie
perl myscript.pl
M.W. Koskamp writes ..
The special variable $| sets the autoflush. See PERLVAR documentation.
Whats this person does is a dirty way of setting $| to a true
value (not 0 or undef).
Default = 0.
why do you say 'dirty' ? .. do you just mean 'less readable' ? .. or are you
implying some other
13 matches
Mail list logo