[15892] in Perl-Users-Digest
Perl-Users Digest, Issue: 3305 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 9 18:11:00 2000
Date: Fri, 9 Jun 2000 15:10:34 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <960588633-v9-i3305@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 9 Jun 2000 Volume: 9 Number: 3305
Today's topics:
exp (raise to a power...) <ekk@ekkinc.com>
Re: exp (raise to a power...) <ekk@ekkinc.com>
Re: exp (raise to a power...) (Craig Berry)
Re: file date parse routine <lauren_smith13@hotmail.com>
Re: file date parse routine <bronsn@hotmail.com>
Re: file date parse routine <lauren_smith13@hotmail.com>
Re: flushing output in perl <methos495@earthlink.net>
Re: Help with a simple regular expression (Bart Lateur)
Re: Help: OOPS Inheritance... <marcel@codewerk.com>
Re: Help: OOPS Inheritance... (Abigail)
How do I call a Oracle stored proc? msabatini@my-deja.com
Re: How do I call a Oracle stored proc? newsposter@cthulhu.demon.nl
Re: JPG img (Bart Lateur)
Re: Larry Rosler interview on perl.com! <dan@tuatha.sidhe.org>
Re: Larry Rosler interview on perl.com! (Bart Lateur)
Re: Larry Rosler interview on perl.com! (Craig Berry)
Re: Larry Rosler interview on perl.com! (Andrew M. Kuchling)
Looking for a perl editor behaving like Qbasic <danielxx@bart.nl>
Re: Net::FTP login problem (Gary E. Ansok)
Re: Net::FTP login problem ogiven@vertex.ucls.uchicago.edu
Newbie question <ernst@cae.ca>
Re: Newbie question <care227@attglobal.net>
Re: Newbie question <ernst@cae.ca>
Re: Newbie question <lauren_smith13@hotmail.com>
Re: Newbie question <sariq@texas.net>
Re: Newbie question <lauren_smith13@hotmail.com>
Re: Newbie question <lr@hpl.hp.com>
Re: Newbie.. Sorry.. <russ_jones@rac.ray.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 09 Jun 2000 05:32:24 -0700
From: EKK <ekk@ekkinc.com>
Subject: exp (raise to a power...)
Message-Id: <3940E3D8.85D35600@ekkinc.com>
Hello,
I found exp for raising e to a certain power,
is there an expression such as C's pow, to raise
any number to the power of x?
Thanks,
AG
--
------------------------------
Date: Fri, 09 Jun 2000 05:43:34 -0700
From: EKK <ekk@ekkinc.com>
Subject: Re: exp (raise to a power...)
Message-Id: <3940E676.4688626C@ekkinc.com>
EKK wrote:
>
> Hello,
>
> I found exp for raising e to a certain power,
> is there an expression such as C's pow, to raise
> any number to the power of x?
>
> Thanks,
>
> AG
> --
...nevermind...
sub log10 {
my $n = shift;
return log($n)/log(10);
}
AG
--
------------------------------
Date: Fri, 09 Jun 2000 18:43:44 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: exp (raise to a power...)
Message-Id: <sk2en0shh5141@corp.supernews.com>
EKK (ekk@ekkinc.com) wrote:
: I found exp for raising e to a certain power,
: is there an expression such as C's pow, to raise
: any number to the power of x?
The ** operator. See perlop.
--
| Craig Berry - http://www.cinenet.net/users/cberry/home.html
--*-- "You live in Los Angeles, and you are going to Reseda; we are
| all in some way or another going to Reseda someday, to die."
- Soul Coughing
------------------------------
Date: Fri, 9 Jun 2000 10:54:56 -0700
From: "Lauren Smith" <lauren_smith13@hotmail.com>
Subject: Re: file date parse routine
Message-Id: <8hrb0c$ef$1@brokaw.wa.com>
Firehawk <bronsn@hotmail.com> wrote in message
news:8hrad7$fgo@news.or.intel.com...
> All,
>
> I've read the online documentation and the camel book looking for a way to
> pull files by date from a specific directory. I know it's there staring
at
> me, but I can't figure out where to look for the answer. Any help would
be
> GREATLY appreciated!
perlfaq5: How do I get a file's timestamp in perl?
Lauren
------------------------------
Date: Fri, 9 Jun 2000 14:11:12 -0700
From: "Firehawk" <bronsn@hotmail.com>
Subject: Re: file date parse routine
Message-Id: <8hrmdv$h7@news.or.intel.com>
Here's my psuedo code for what I want to do and the answer doesn't appear to
be in the perlfaq5:
On and NT exchange server:
loop through all files in a specified directory
read the file date
if older than 2 days, then delete file
thanks
"Lauren Smith" <lauren_smith13@hotmail.com> wrote in message
news:8hrb0c$ef$1@brokaw.wa.com...
>
> Firehawk <bronsn@hotmail.com> wrote in message
> news:8hrad7$fgo@news.or.intel.com...
> > All,
> >
> > I've read the online documentation and the camel book looking for a way
to
> > pull files by date from a specific directory. I know it's there staring
> at
> > me, but I can't figure out where to look for the answer. Any help would
> be
> > GREATLY appreciated!
>
> perlfaq5: How do I get a file's timestamp in perl?
>
> Lauren
>
>
>
------------------------------
Date: Fri, 9 Jun 2000 14:40:28 -0700
From: "Lauren Smith" <lauren_smith13@hotmail.com>
Subject: Re: file date parse routine
Message-Id: <8hro7a$nkq$1@brokaw.wa.com>
Firehawk <bronsn@hotmail.com> wrote in message
news:8hrmdv$h7@news.or.intel.com...
> Here's my psuedo code for what I want to do and the answer doesn't appear
to
> be in the perlfaq5:
>
> On and NT exchange server:
> loop through all files in a specified directory
> read the file date
> if older than 2 days, then delete file
If you know how to get all the files in a directory: opendir(), readdir()...
and you know how to loop: for, while...
and you've obviously read the FAQ which explains how to determine how old a
file is...
then you don't have a Perl question any more. :-) Congratulations!
If OTOH, you don't know about those functions above, now is a good time to
learn about perldoc. Perldoc (lowercase that 'P') is a utility that
searches the documentation for keywords that you specify at the command
line. Type this into a command window:
perldoc perldoc
Now you have a list of commands that perldoc understands. Perldoc is really
handy for those times you are stuck, but need an answer really quickly.
Lauren
------------------------------
Date: Fri, 09 Jun 2000 18:29:48 GMT
From: methos <methos495@earthlink.net>
Subject: Re: flushing output in perl
Message-Id: <39413880.7813479B@earthlink.net>
You might want to see if you can do anything with FileHandle.pm, and
the autoflush function.
this might be able to help you out.
--
- Methos -
"Blaming the Internet for societies problems is like blaming paper for
bad poetry"
- anonymous -
salvadorej@my-deja.com wrote:
> How does one flush output in perl? I'm having some problems with
> a few things mysteriously coming out before the "Content-type" line
> in a CGI script, and I'm thinking this might help. I'd prefer trying
> to do this w/o the standard modules...
>
> --
> ============================================================
> "The best laid plans of mice and men are about equal"
> iowa_so8ng@hot8mail.com
> Adress is spam-resistant; remove eight's to reach me.
> Also, the header address (salvadoreh)is spam-bait.
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
------------------------------
Date: Fri, 09 Jun 2000 20:03:58 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Help with a simple regular expression
Message-Id: <39434d95.1342476@news.skynet.be>
Marco Natoni wrote:
>Tad McClellan wrote:
>> "Perl" is used to refer to the language proper.
>> "perl" is used to refer to the implementation of the language,
>> (the interpreter).
>> "PERL" is not used.
>
> Is that codified or just a current use? Many language or system names
>being acronyms are referred in all uppercase (such as MVS, sometimes
>FORTRAN...).
Just a hint: "perl" is not really an acronym...
--
Bart.
------------------------------
Date: Fri, 09 Jun 2000 20:13:50 GMT
From: Marcel Grunauer <marcel@codewerk.com>
Subject: Re: Help: OOPS Inheritance...
Message-Id: <Pine.LNX.4.21.0006092215030.9537-100000@codewerk.com>
On 9 Jun 2000, Abigail wrote:
> On 09 Jun 2000 13:24:23 +0200, Gisle Aas <gisle@ActiveState.com> wrote:
> ++
> ++ It is generally a bad idea to inherit from Exporter when you write a
> ++ OO module.
>
> Why?
The following are not my words, just quoted (without permission, sorry
if that was wrong) from Damian Conway's Object Oriented Perl, but they
make sense to me:
"[...] What subroutines should we export from an object-oriented module?
And the answer is, absolutely none!
The entire point of building a class is to encapsulate attributes and
methods within the namespace of that class to ensure that they're accessed
in a controlled manner. Exporting a class's attributes would compromise
that encapsulation, so there's no reason to export any variables from
an object-oriented module.
Exporting the methods of a class usually doesn't make much sense either,
since methods are always supposed to be called through an invoking object,
or through the package itself. In either case, Perl will automatically
look for the method in the namespace of the class package, not the
namespace to which subroutines are exported."
--
Marcel
perl -e 'print unpack(q$u$,q$82G5S="!!;F]T:&5R(%!E<FP@2&%C:V5R$)'
------------------------------
Date: 9 Jun 2000 20:42:59 GMT
From: abigail@arena-i.com (Abigail)
Subject: Re: Help: OOPS Inheritance...
Message-Id: <8hrks9$jqk$1@news.panix.com>
On Fri, 09 Jun 2000 20:13:50 GMT, Marcel Grunauer <marcel@codewerk.com> wrote:
++ On 9 Jun 2000, Abigail wrote:
++
++ > On 09 Jun 2000 13:24:23 +0200, Gisle Aas <gisle@ActiveState.com> wrote:
++ > ++
++ > ++ It is generally a bad idea to inherit from Exporter when you write a
++ > ++ OO module.
++ >
++ > Why?
++
++ The following are not my words, just quoted (without permission, sorry
++ if that was wrong) from Damian Conway's Object Oriented Perl, but they
++ make sense to me:
++
++ "[...] What subroutines should we export from an object-oriented module?
++
++ And the answer is, absolutely none!
++
++ The entire point of building a class is to encapsulate attributes and
++ methods within the namespace of that class to ensure that they're accessed
++ in a controlled manner. Exporting a class's attributes would compromise
++ that encapsulation, so there's no reason to export any variables from
++ an object-oriented module.
++
++ Exporting the methods of a class usually doesn't make much sense either,
++ since methods are always supposed to be called through an invoking object,
++ or through the package itself. In either case, Perl will automatically
++ look for the method in the namespace of the class package, not the
++ namespace to which subroutines are exported."
I dunno.
I'd rather type:
use Module;
...
my $obj = Module -> new;
...
my $result = $obj -> method ();
if ($result == E_FOO) {
save_the_world;
}
elsif ($result == E_BAR) {
save_the_whales;
}
than
if ($result == Module -> E_FOO) {
Module::save_the_world;
}
elsif ($result == Module -> E_BAR) {
Module::save_the_whales;
}
Abigail
------------------------------
Date: Fri, 09 Jun 2000 18:35:28 GMT
From: msabatini@my-deja.com
Subject: How do I call a Oracle stored proc?
Message-Id: <8hrdde$b9c$1@nnrp1.deja.com>
How do I call an Oracle stored procedure or function stored on a
remote server from a local perl script?
The function returns a string.
The remote function returning a String is written in java and stored
successfully. Now I want to call this.
Here is part of the code
...
$obh = DBI->connect( "<db_alias>", "<login>", "<passwd>", "Oracle")
$sth = $obh->prepare("call remote_func()"); # is this correct?
...
Not sure of the above syntax. The remote func returns a String.
I tried the Oracle site, not much to go on there.
Thanks.
-Mark Sabatini
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 9 Jun 2000 21:33:54 GMT
From: newsposter@cthulhu.demon.nl
Subject: Re: How do I call a Oracle stored proc?
Message-Id: <8hrns2$45r$1@internal-news.uu.net>
msabatini@my-deja.com wrote:
> How do I call an Oracle stored procedure or function stored on a
> remote server from a local perl script?
> The function returns a string.
Try this:
my $sth = $dbh->prepare (q{
BEGIN
:res := RADIUS_LIB_PKG.create_profile_value_seq (:id);
END;
});
$sth->bind_param_inout (":res", \$res, 10);
$sth->bind_param (":id", $id, {ora_type => ORA_VARCHAR2});
$sth->execute;
Erik
------------------------------
Date: Fri, 09 Jun 2000 20:07:08 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: JPG img
Message-Id: <39444ded.1430247@news.skynet.be>
Chello wrote:
>I'd like to know how to dispklay a JPG picture. I know how to do it with GIF
>but not with JPG. Does anybody have a solution?
Use an image viewer.
Seriously, are you sure you're in the right newsgroup? Because I
wouldn't know how to show a GIF file.
And if you mean: "send to browser", it's just the same as wit ha GIF
file. The mime type in the content-type header must be "image/jpeg"
instead of "image/gif", but that's it.
--
Bart.
------------------------------
Date: Fri, 09 Jun 2000 19:49:18 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: Larry Rosler interview on perl.com!
Message-Id: <2Tb05.108271$hT2.428202@news1.rdc1.ct.home.com>
Ala Qumsieh <aqumsieh@hyperchip.com> wrote:
> Dan Sugalski <dan@tuatha.sidhe.org> writes:
>> Ah, ya caught me. :) Can't think of a good place to stick in a use of
>> rand, alas. Maybe in the memory allocation code...
> I always had the impression that a rand() was stealthily used by perl
> behind the scenes every time it encountered something like:
> *{"${foreign_package}::$foreign_sub"} = \&{"${my_package}::$my_sub"};
Nah, that runs the current interpreter's memory image through the MD5
checksum code and the resulting number split into 32-bit chunks which are
all xor'd together to get the real memory address of the start of the
optree for the sub.
Hardly random... :-)
Dan
------------------------------
Date: Fri, 09 Jun 2000 20:51:57 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Larry Rosler interview on perl.com!
Message-Id: <394754c4.3181530@news.skynet.be>
Drew Simonis wrote:
>From the interview:
>
>:There's certainly no ANSI Perl. Does Perl need the same kind of
>:official standardization that C got?
>:
>:LR: I believe that it does, in order to increase its acceptability.
>:Many organizations either cannot or will not endorse the use of
>:unstandardized languages in their business-critical activities.
>
>
>Here here!
Allow me to disagree.
If Perl was ANSI-standardized, that would open the door for other
vendors to build their own interpreters, and actually legally call it
"Perl". The next step would be they'd "enhance" the language (have you
ever seen a C compiler without any vendor-specific "enhancements"?), and
the third and final step would be they could try and break away from the
original language. Remember what some company tried to do to Java with
their "J++"...
No, I prefer the /one source for all ports/ approach, firmly in the
hands of a few very competent and well-respected (by each other ;-)
people. That is the situation now with Perl.
Secondly, a standardized Perl would disallow the original perl
developers to continue their work, i.e. add new language features...
--
Bart.
------------------------------
Date: Fri, 09 Jun 2000 21:38:17 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Larry Rosler interview on perl.com!
Message-Id: <sk2ou94hh5172@corp.supernews.com>
Bart Lateur (bart.lateur@skynet.be) wrote:
: If Perl was ANSI-standardized, that would open the door for other
: vendors to build their own interpreters, and actually legally call it
: "Perl". The next step would be they'd "enhance" the language (have you
: ever seen a C compiler without any vendor-specific "enhancements"?), and
: the third and final step would be they could try and break away from the
: original language. Remember what some company tried to do to Java with
: their "J++"...
[snip]
: Secondly, a standardized Perl would disallow the original perl
: developers to continue their work, i.e. add new language features...
Seems like your two objections contradict one another. In point of fact,
language standardization merely specifies a reliable minimum language
subset which *must* be implemented and behave in particular ways. Each
vendor may offer extensions, so long as they don't interfere with the core
subset. So the current perl dev team could continue their blessed work;
the only change would be that their new stuff would not be 'official'
(required of all conforming implementations) until it got ANSI approval.
--
| Craig Berry - http://www.cinenet.net/users/cberry/home.html
--*-- "You live in Los Angeles, and you are going to Reseda; we are
| all in some way or another going to Reseda someday, to die."
- Soul Coughing
------------------------------
Date: 09 Jun 2000 17:43:25 -0400
From: akuchlin@mems-exchange.org (Andrew M. Kuchling)
Subject: Re: Larry Rosler interview on perl.com!
Message-Id: <3dhfb2il8i.fsf@amarok.cnri.reston.va.us>
rurban@x-ray.at (Reini Urban) writes:
> lisp, C, C++ e.g. had to be standardized because of
> multiple competing implementations and vendors vs. the big user
> community, but languages like python or perl will never need that.
> esp. after ActiveWare (my only fear some years ago) being incoorporated
> into the 5.6 process. same with mark hammond with pythonwin. it's not
Sometimes competing implementations are just what you want; compare
python vs. jpython vs. vyper. Three implementations, in three
different languages. (Or Tcl and Jacl.) At this point you do need
some consensus, though perhaps only an informal one, on what
behaviours are part of the language and which ones are accidents of a
specific implementation.
--
A.M. Kuchling http://starship.python.net/crew/amk/
Every man is wise when attacked by a mad dog; fewer when pursued by a mad
woman; only the wisest survive when attacked by a mad notion.
-- Robertson Davies, _Marchbanks' Almanac_
------------------------------
Date: Fri, 09 Jun 2000 20:16:19 GMT
From: "Daniel van den Oord" <danielxx@bart.nl>
Subject: Looking for a perl editor behaving like Qbasic
Message-Id: <ngc05.684$%h3.12960@Typhoon.bART.nl>
I'm searching for a perl editor behaving like a Qbasic editor..
Especially for the Subs !!
Each sub must be able to be opened in another window.. and the main window
just contains the main part of the program calling all those subs ! anybody
seen such a program ?
Daniel van den Oord ( Daniel304 RTCL )
It's nice to be important, but it's more important to be nice
See there be good bye bye
Daniel304rt ResearchTriangle Community Leader
http://www.geocities.com/ResearchTriangle/Forum/5577
------------------------------
Date: 9 Jun 2000 18:49:59 GMT
From: ansok@alumni.caltech.edu (Gary E. Ansok)
Subject: Re: Net::FTP login problem
Message-Id: <8hre8n$fpi@gap.cco.caltech.edu>
In article <8hr1rt$20f$1@nnrp1.deja.com>,
<ogiven@vertex.ucls.uchicago.edu> wrote:
>i'm pulling the username,password for a Net::FTP -> login from a
>database.....and although getting the hostname this way works fine, it
>breaks the login process......
>
>when i do it like this, it works:
>
>$username='user';
>$password='password';
>
>$ftp = Net::FTP->new($hostname);
>$ftp->login($username, $password);
>
>but like this, it doesn't:
>
>$statement="SELECT username, password FROM databasetable'";
>$sth=$dbh->prepare($statement);
>$sth->execute;
>($username,$password) = $sth->fetchrow;
>
>$ftp = Net::FTP->new($hostname);
>$ftp->login($username, $password);
>
>even though $username, $password print out exactly the same in both
>cases.........i've not been able to find any relevant info in the module
>docs or on usenet.....so, any suggestions would be much appreciated.....
Make sure that $username and $password contain *exactly* what you think
they do -- trailing spaces and newlines are difficult to see when you
just print out the strings without delimiters. Some databases will pad
strings out to the column width (depending on the column type), so maybe
this is what's happening.
print "User = <<$username>>, Pass = <<$password>>\n";
If I'm especially paranoid, I'll print out the length of each string, too.
In the Perl debugger, use "x $username" and "x $password" -- these will
put quotes around the string value, and also display any weird control
characters that might have made their way into the string.
-- Gary
------------------------------
Date: Fri, 09 Jun 2000 20:54:19 GMT
From: ogiven@vertex.ucls.uchicago.edu
Subject: Re: Net::FTP login problem
Message-Id: <8hrlhj$hrt$1@nnrp1.deja.com>
> Make sure that $username and $password contain *exactly* what you
think
> they do -- trailing spaces and newlines are difficult to see when you
> just print out the strings without delimiters. Some databases will
thanks alot. there *was* trailing whitespace causing the problem.
olivia
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 9 Jun 2000 14:47:29 -0400
From: "Ernst P" <ernst@cae.ca>
Subject: Newbie question
Message-Id: <8hre43$pfo$1@dns3.cae.ca>
Hi.
I have a newbie question. I have an ASCI file with fixed length record. I'm
looking for an efficent way off reading from this file without doing a lot
of assignments to set each variable one at a time. I know we can use FORMAT
and WRITE to generate reports. Is there a way to READ from a FORMAT ?
Thanks,
Ernst
------------------------------
Date: Fri, 09 Jun 2000 15:01:59 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: Newbie question
Message-Id: <39413F27.1C1CAE03@attglobal.net>
Ernst P wrote:
>
> Hi.
> I have a newbie question. I have an ASCI file with fixed length record. I'm
> looking for an efficent way off reading from this file without doing a lot
> of assignments to set each variable one at a time. I know we can use FORMAT
> and WRITE to generate reports. Is there a way to READ from a FORMAT ?
> Thanks,
> Ernst
Sample of the report format? Sample of some code you've tried?
Sample of what you'd like the output to look like? Somthing,
anything to help.
------------------------------
Date: Fri, 9 Jun 2000 15:06:50 -0400
From: "Ernst P" <ernst@cae.ca>
Subject: Re: Newbie question
Message-Id: <8hrf8d$7pb$1@dns3.cae.ca>
Hello again,
I realize that my question may not be clear. here is what I meant. I have a
file with the following format:
column :1234567890
data :ABBBCCDDDD
Let's say I want to have $a = "A"; $b="BBB"; $c="CC"; $d="DDDD"; Is there
an easier way to do this than
$line = <FILE>;
@line = split (//,$line);
$a = shift @line;
$b = join (//, splice (@line, 0 ,3));
$d = join (//, splice (@line,0,4));
$c = join (//, splice (@line,0,1));
Thanks,
Ernst
Ernst P <ernst@cae.ca> wrote in message news:8hre43$pfo$1@dns3.cae.ca...
> Hi.
> I have a newbie question. I have an ASCI file with fixed length record.
I'm
> looking for an efficent way off reading from this file without doing a lot
> of assignments to set each variable one at a time. I know we can use
FORMAT
> and WRITE to generate reports. Is there a way to READ from a FORMAT ?
> Thanks,
> Ernst
>
>
>
------------------------------
Date: Fri, 9 Jun 2000 12:14:57 -0700
From: "Lauren Smith" <lauren_smith13@hotmail.com>
Subject: Re: Newbie question
Message-Id: <8hrfme$508$1@brokaw.wa.com>
Ernst P <ernst@cae.ca> wrote in message news:8hre43$pfo$1@dns3.cae.ca...
> Hi.
> I have a newbie question. I have an ASCI file with fixed length record.
I'm
> looking for an efficent way off reading from this file without doing a lot
> of assignments to set each variable one at a time. I know we can use
FORMAT
> and WRITE to generate reports. Is there a way to READ from a FORMAT ?
It sounds like a neat idea to have a template-read. Something along the
lines of writing data out using a template, then using the same template to
read back in previously archived data. In essence, you would be doing a
block read and split, but not have to worry about assigning variables
yourself. This may result in the ambiguity of those variables' lifetime,
though.
Unfortunately, I don't know if Perl has any way to do this.
Lauren
------------------------------
Date: Fri, 09 Jun 2000 14:57:19 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: Newbie question
Message-Id: <39414C1F.F8C04BE7@texas.net>
Ernst P wrote:
>
> Hi.
> I have a newbie question. I have an ASCI file with fixed length record. I'm
> looking for an efficent way off reading from this file without doing a lot
> of assignments to set each variable one at a time. I know we can use FORMAT
> and WRITE to generate reports. Is there a way to READ from a FORMAT ?
perldoc -q fixed
Reading the documentation is somewhat more expeditious than waiting for
an answer from Usenet.
- Tom
------------------------------
Date: Fri, 9 Jun 2000 13:10:09 -0700
From: "Lauren Smith" <lauren_smith13@hotmail.com>
Subject: Re: Newbie question
Message-Id: <8hriu0$50k$1@brokaw.wa.com>
Ernst P <ernst@cae.ca> wrote in message news:8hrf8d$7pb$1@dns3.cae.ca...
> I realize that my question may not be clear. here is what I meant. I have
a
> file with the following format:
>
> column :1234567890
> data :ABBBCCDDDD
>
> Let's say I want to have $a = "A"; $b="BBB"; $c="CC"; $d="DDDD"; Is there
> an easier way to do this than
> $line = <FILE>;
> @line = split (//,$line);
> $a = shift @line;
> $b = join (//, splice (@line, 0 ,3));
> $d = join (//, splice (@line,0,4));
> $c = join (//, splice (@line,0,1));
$data = <DATA>;
($a, $b, $c, $d) = $data =~ /(.)(...)(..)(....)/;
print "\$a: $a\n";
print "\$b: $b\n";
print "\$c: $c\n";
print "\$d: $d\n";
__DATA__
ABBBCCDDDD
Output:
$a: A
$b: BBB
$c: CC
$d: DDDD
Of course, if you had used some sort of delimiter in your data you could
have done a split()
$data = <DATA>;
($a, $b, $c, $d) = split (/\|/, $data);
print "\$a: $a\n";
print "\$b: $b\n";
print "\$c: $c\n";
print "\$d: $d\n";
__DATA__
A|BBB|CC|DDDD
But I wouldn't want to tell you how to format your own data. :-)
Lauren
------------------------------
Date: Fri, 9 Jun 2000 13:31:27 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Newbie question
Message-Id: <MPG.13aaf3fe5db921ad98ab5a@nntp.hpl.hp.com>
[You jeopardized yourself. I have sorted it out and reformatted the
lines so one can follow the discourse rationally. Your Subject: is
absurd, and will immediately have led many potential responders to
ignore the question completely.]
> Ernst P <ernst@cae.ca> wrote in message news:8hre43$pfo$1@dns3.cae.ca...
> > I have a newbie question. I have an ASCI file with fixed length record.
> > I'm looking for an efficent way off reading from this file without
> > doing a lot of assignments to set each variable one at a time. I know
> > we can use FORMAT and WRITE to generate reports. Is there a way to
> > READ from a FORMAT ?
In article <8hrf8d$7pb$1@dns3.cae.ca> on Fri, 9 Jun 2000 15:06:50 -0400,
Ernst P <ernst@cae.ca> says...
> I realize that my question may not be clear. here is what I meant. I have a
> file with the following format:
>
> column :1234567890
> data :ABBBCCDDDD
>
> Let's say I want to have $a = "A"; $b="BBB"; $c="CC"; $d="DDDD"; Is there
> an easier way to do this than
> $line = <FILE>;
> @line = split (//,$line);
> $a = shift @line;
> $b = join (//, splice (@line, 0 ,3));
> $d = join (//, splice (@line,0,4));
> $c = join (//, splice (@line,0,1));
Ook. Once again, the character-at-a-time paradigm strikes. The
performance of that code would be frightful.
There are at least three better ways:
1. regex: my ($a, $b, $c, $d) = $line =~ /(.)(...)(..)(....)/s;
2. substr: my ($a, $b, $c, $d) = (substr($line, 0, 1),
substr($line, 1, 3),
substr($line, 4, 2),
substr($line, 6, 4));
3. unpack: my ($a, $b, $c, $d) = unpack 'A1 A3 A2 A4' => $line;
My preference by far is the last one, but YMMV.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 09 Jun 2000 13:57:20 -0500
From: Russ Jones <russ_jones@rac.ray.com>
Subject: Re: Newbie.. Sorry..
Message-Id: <39413E10.FA8086C8@rac.ray.com>
Bart Lateur wrote:
>
> Yanik Rondeau wrote:
>
> >Please can somebody let me know what I need (software) to start
> >programming Perl. Which tools / software?
>
> ...And you need a text editor, preferably one that will
> allow you to run external "tools" (=perl) with your current file as a
> parameter, and which captures STDOUT and STDERR into a window. Many
> "programmer's editors" have this facility. BTW syntax highlighting is
> nice, too.
>
DISCLAIMER
This is not an editor-war troll. Or a Capitalization War Troll.
A free editor with all the features Bart mentioned, including syntax
highlighting for a ton of languages as well as Perl, is vim (vi
improved). It's available for Windows, Unix, probably other platforms.
It works just like vi; some consider that a plus, others don't.
--
Russ Jones - HP OpenView IT/Operatons support
Raytheon Aircraft Company, Wichita KS
russ_jones@rac.ray.com 316-676-0747
When cryptography is outlawed, only outlaws will
A2bgg c4dc8 aji0i knS4E 7eFj8 22Rl1
ZdGg3 gu8i6 lu12N s6NoG gn3g3 q835n
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 3305
**************************************