[6717] in Perl-Users-Digest
Perl-Users Digest, Issue: 342 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 22 09:17:16 1997
Date: Tue, 22 Apr 97 06:00:44 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 22 Apr 1997 Volume: 8 Number: 342
Today's topics:
Re: -e switch <dehon_olivier@jpmorgan.com>
[Q] who to return images (Roman Bloeth)
Re: A Perl modules confusion... <ajs@ajs.com>
Re: evaluating an expression (SysAdmin)
Re: Filename Wildcard Command-line Interpolation (Honza Pazdziora)
Re: help: find pattern, then go down 3 lines (Niksun)
Re: help: find pattern, then go down 3 lines <a.aitken@unl.ac.uk>
Re: help: find pattern, then go down 3 lines (Tad McClellan)
Re: How to expand a variable in a string? <a.aitken@unl.ac.uk>
Re: How to expand a variable in a string? <ajs@ajs.com>
Re: Lisp is neither (was Re: Ousterhout and Tcl lost th <benh@cristie.co.uk>
Re: Module naming question: Net::Rcmd? <gbarr@ti.com>
Re: Name that OS(unix,nt,?) question. (Bradley J. Marker)
Re: Perl as its own metalanguage? (Malcolm Beattie)
Re: perl mkdir produces weird permissions (Honza Pazdziora)
Re: perl mkdir produces weird permissions <a.aitken@unl.ac.uk>
Re: perl mkdir produces weird permissions <tchrist@mox.perl.com>
Perl profiler Chris_Houck@i2.com
Re: Perl profiler <dehon_olivier@jpmorgan.com>
Q: How to sort an array of arrays <harry@bci.se>
Reading this will take seconds! <Sly@yournamehere.com>
Re: Regular expression question <a.aitken@unl.ac.uk>
Re: Unix and ease of use (WAS: Who makes more ...) (James Youngman)
Re: Unix and ease of use (WAS: Who makes more ...) (James Youngman)
Re: Who will win? Borland or Microsoft or Programmers? <kischobb@immd9.informatik.uni-erlangen.de>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 22 Apr 1997 10:00:48 +0100
From: Olivier Dehon <dehon_olivier@jpmorgan.com>
Subject: Re: -e switch
Message-Id: <njz7mhvph33.fsf@jpmorgan.com>
Bill Banyai <banyai@llnl.gov> writes:
>
> I am a newby and just installed version 5.003_07 on Win95 100MHz
> pentium.
>
> When I enter: perl -e 'print("hello\n");'
> I see a blank line and then a c:\ on the next line; e.g.
> c:\ perl -e 'print("hello\n");'
>
> c:\
> Wnen I save print("hello\n"); to file test.prl and run perl test.prl,
> then the blank line is replaced by hello; e.g.
> c:\ perl test.prl
> hello
> c:\
>
> Any ideas about why -e is not working?
>
> Another clue is that when I enter perl -e 'print "hello\n";'
> then I received an error message:
> "Can't find string terminator "'" anywhere before EOF at -e on line 1."
> It appears to be sensitive to the space between print and "hello\n"
>From what I could figure out (I am not a DOS expert):
In MSDOS, the single quote (') is not a special character.
Which means that when you do
perl -e 'print("hello\n");'
the args that are passed to the perl interpreter are
-e and
'print("hello\n");' (and not print("hello\n"); ;-)
You should use double quotes and backslashify your perl expression as needed.
E.G.:
c:\ perl -e "print(\"hello\\n\");"
hello
c:\
At least, this last command line works for me.
Hope this helps.
Olivier Dehon.
------------------------------
Date: 22 Apr 1997 10:33:00 +0100
From: Roman@pussycat.ping.de (Roman Bloeth)
Subject: [Q] who to return images
Message-Id: <6VMu0xZ4jQB@pussycat.ping.de>
Hi folks!
I'm a perl-beginner and started learning perl for being able to write CGI-
scripts (isn't that one of the main uses for perl?). It's really easy to
return (HTML-) text from a perl program. But then I've seen perl-scripts
being called out of HTML-pages using <IMG SRC="your_perl_here.cgi">. So
doesn't that mean that these so invoked perl-scripts won't return text but
instead output images in a binary form?!
How would one do this?
Awaiting a hint or two,
Roman.
Mutants for nuclear power! }-)
------------------------------
Date: Tue, 22 Apr 1997 09:25:27 -0400
From: Aaron Sherman <ajs@ajs.com>
To: Gandalf D'Grey <grimaldo@IAEhv.nl>
Subject: Re: A Perl modules confusion...
Message-Id: <335CBC47.3DD7@ajs.com>
Gandalf D'Grey wrote:
>
> D. Emilio Grimaldo T. (grimaldo@panama.iaehv.nl) wrote:
> : Hi,
> : I am converting a 4.x package to a 5.003 version, however I
> : am getting the impression that this 'module' stuff is more a
>
> Fixed it:
>
> 1. I still think the modules thing is a bit sloppy, and teh
> class/object thing I don't want even to look at, seems so
> yuk and fragile. For those things I would rather stick to
> a development language. I guess Python is a bit more
> refined in additions to the language but aside from that I
> am a PIG fan (Perl Is Great)
How sloppy? Fragile? Have you looked at the library?
>
> 2. I overlooked that I can only use ONE Export statement with
> everthing in it...
>
What is an "Export statement"? Do you mean setting the @EXPORT array?
What about:
@EXPORT = qw(foo bar);
push(@EXPORT, qw(baz bif));
$EXPORT[4] = 'another';
$EXPORT[0] =~ s/oo/n/;
#...
> 3. Also the 'import' thing, It was overriding the import routine
> of Exporter! I misunderstood the PODs, but then I did it
> BECAUSE:
>
> I need to do something during module import which
> makes use of the 'configuration' variables, the
> problem is that BEGIN is oblivious of all of them
> because it has not interpreted them yet... Shame.
>
> It would be a GOOD idea to extend the Exporter module
> so that it can call a user defined import routine
> *after* it has done it's own internal import.
Just put the code in your module. It's real perl, no limitations,
you don't have to use BEGIN, the whole module gets parsed and
executed.
I think that the problem that you are running into is that you
are thinking of a module as a configuration file. It is not.
It is, in fact, perl code. There are some variables which you
are expected to set (among them being @EXPORT, @EXPORT_OK, $VERSION,
@ISA, etc), but how you set them, and what else you do is your
business. If it makes you feel better, just write:
package mypack;
require Exporter;
@EXPORT=qw(a b);
@EXPORT_OK=qw(a b);
@ISA=qw(Exporter);
initialize_mypack();
sub initialize_mypack {
...
}
sub a {
}
sub b {
}
1;
__END__
Import should only be augmented or overridden if you want to change
the way symbols are exported from your module. As an example,
if you wanted to export variables that were generated at run-
time or tied to external information, you might override
import (see Env.pm).
-AJS
--
Aaron Sherman "We are, all of us, living in the shadow of
Safety Net Solutions Manhatten." -The Watchmen
Email: ajs@ajs.com
WWW: http://ajs.com/~ajs/
------------------------------
Date: 22 Apr 1997 11:02:01 GMT
From: matrix@I_should_put_my_domain_in_etc_NNTP_INEWS_DOMAIN (SysAdmin)
Subject: Re: evaluating an expression
Message-Id: <5ji5ra$994@news.nfinity.com>
Stephan Nagy (steph@ciris.net) wrote:
: There is probably a simple solution to this, but i can't figure it out.
: how do i evaluate an expression to see if it is divisible by a number. or
: in other words.
: if ( (sumnumber/4) == a whole number) {
^^^^^^^^^^^^^^^ <- How 'bout an int function?
if ( (sumnumber/4) == int(sumnumber/4)) {
: @DaysInMonth=31,29,31,30,31,30,31,31,30,31,30,31
: }
: elsif ((sumnumber/4) != a whole number) {
^^^^^^^^^^^^^^^<--- same here
: @DaysInMonth=31,28,31,30,31,30,31,31,30,31,30,31
: }
: can i do this? if so how? any assistance is appreciated.
Your welcome =)
: stephan nagy
: rzjj60@email.sps.mot.com
: or
: steph@ciris.net
------------------------------
Date: Tue, 22 Apr 1997 07:53:35 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: Filename Wildcard Command-line Interpolation
Message-Id: <adelton.861695615@aisa.fi.muni.cz>
> >I'm afraid that there's no way to avoid some kind of quotes (single
> > or double). It's because before a script in a shell is really
> > executed the shell (I assume you are using some kind of UNIX ...)
> > does filename interpolation (extending all '*' and '?' to lists
> > of names) and the only way to prevent the shell from doing this is
> > (as far as I know) using quotes.
> >
>
> At first I swallowed this, now I am wondering if it is really true. Surely
> grep wouldn't work if this were the case now, would it? Or am I missing
> something here?
>
> And I don't see why Win32 Perl should behave this way either, the shell
> doesn't do filename interpolation there.
I am sure about Windoze, but will speak about general operating
systems.
> Can some one enlighten me here? I too would like to write a script that
> takes a wildcard, and I really don't want to quote the argument, or
> backslash the asterixes.
First thing you have to understand is the difference between what is
inside you perl script and what is outside. If you have some data in
@ARGV, you can do various things with them. But from inside perl you
cannot affect the data that come into that @ARGV. You can manipulate
with this array, but have to accept the fact that your script cannot
say to the shell or other program that calls it, which data and what
way they should get into that array.
The problem is that the expansion of the shell metacharacters, which
will produce the list of files, is done just because this is how the
shell programs tend to work. There is no helps saying I really don't
want to quote the argument. It simply is so that if you want to pass
over certain characters into your programs (no matter if they are in
perl or C or VB ;-) and shell does expansion, you just have to quote
them.
As for the grep, you can try to call it with
grep bt* file versus grep 'bt*' file
and see the difference (provided you have files of that name in your
directory.
Hope this made it clear.
--
------------------------------------------------------------------------
Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
I can take or leave it if I please
------------------------------------------------------------------------
------------------------------
Date: Tue, 22 Apr 1997 06:23:29 GMT
From: niksun@lconn.net (Niksun)
Subject: Re: help: find pattern, then go down 3 lines
Message-Id: <335c56d6.16884616@news.inetw.net>
Try this:
...
open(FILE,"filename goes here");
@lines = <FILE>;
close(FILE);
foreach ($i = 0; $i <= @lines; $i++) {
if ($lines[$i] =~ /pattern/i) {
$my_value = substr($lines[$i+3], 4, 2);
}
}
...
The 5th and 6th characters of the 3rd line below your matched pattern
will be saved in $my_value.
Niksun
-----
On Tue, 22 Apr 1997 03:30:56 GMT, david@penney.mv.com (David Penney)
wrote:
>Hi,
>
>I have a file that I want to read and look for a pattern. When I find
>the pattern, I would like to go down 3 lines in the file and read in
>the value (actually the 5th and 6th character on that line but I
>think I can figure that one out) on that line and continue reading in
>the file. I'm pretty sure it's straightforward but am having trouble.
>Could someone help?
>
>while (<>)
> if (/pattern/)
> ?????
>
>Any input would be appreciated.
>
>Thank you,
>
>David
>david@penney.mv.com
------------------------------
Date: Tue, 22 Apr 1997 10:55:45 +0100
From: Alastair Aitken <a.aitken@unl.ac.uk>
Subject: Re: help: find pattern, then go down 3 lines
Message-Id: <335C8B21.5480C319@unl.ac.uk>
David Penney wrote:
> I have a file that I want to read and look for a pattern. When I
> find
> the pattern, I would like to go down 3 lines in the file and read in
>
> the value (actually the 5th and 6th character on that line but I
> think I can figure that one out) on that line and continue reading
> in
> the file. I'm pretty sure it's straightforward but am having
> trouble.
> Could someone help?
>
> while (<>)
> if (/pattern/)
> ?????
Set up a count when you find the pattern and just count through the
three lines:
$count = 0;
$test = 0;
while ( <> ) {
$count++;
if ($test == ($count + 3)) {
&process_line;
}
if (/$pattern/) {
$test = $count;
}
}
Alastair.
------------------------------
Date: Tue, 22 Apr 1997 05:03:12 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: help: find pattern, then go down 3 lines
Message-Id: <0d2ij5.2h.ln@localhost>
David Penney (david@penney.mv.com) wrote:
: Hi,
: I have a file that I want to read and look for a pattern. When I find
: the pattern, I would like to go down 3 lines in the file and read in
: the value (actually the 5th and 6th character on that line but I
: think I can figure that one out) on that line and continue reading in
: the file. I'm pretty sure it's straightforward but am having trouble.
: Could someone help?
: while (<>)
: if (/pattern/)
{
<>; # discard one line I'm not checking for end of file here though
<>; # discard second line
$third_line = <>;
}
: ?????
: Any input would be appreciated.
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Tue, 22 Apr 1997 10:49:13 +0100
From: Alastair Aitken <a.aitken@unl.ac.uk>
Subject: Re: How to expand a variable in a string?
Message-Id: <335C8998.6CF973A0@unl.ac.uk>
Petr Prikryl wrote:
> I have read a string into my variable $str. The string may be
> something
> like this:
> "some text $variable and some text again"
>
> I mean, when: $variable = "HELLO";
> then the string will be "some text HELLO and some text again" after.
You can use eval():
$str = eval("string with $var in it");
But this is unnecessary as variable interolation will occur in double
quoted strings without the use of eval. I assume therefore that you are
reading the string in from a separate file through somethng like open()
and while ().
If the string is in a separate file then you can require the file, which
is a form of eval for reading in external files.
require file_with_string_in_it;
If you require the file then it should be in a form that perl recognises
as a library or a package. If it's a library it must return a true
value - which can be achieved by having the last line of the file as:
1;
If you do this the file will be parsed once by the require function and
variable interpolation will be carried out then. Make sure that the
variables in the file have values in them before you require the file so
that interpollation results in something meaningful.
Alastair.
------------------------------
Date: Tue, 22 Apr 1997 09:02:34 -0400
From: Aaron Sherman <ajs@ajs.com>
To: David Alan Black <dblack@icarus.shu.edu>
Subject: Re: How to expand a variable in a string?
Message-Id: <335CB6EA.72BD@ajs.com>
David Alan Black wrote:
> >I have read a string into my variable $str. The string may be something
> >like this:
> > "some text $variable and some text again"
> It's very easy. You have no idea how easy it is....
> Just run your code and watch the magic :-)
> P.S. To answer your next question: "The amount was \$10.00."; # :-)
Note the words "read a string". Perhaps this indicates some sort of
I/O (like, oh, say reading in a string that the user types...)
There are several answers, but which one is correct depends on
your application. For instance:
eval "\$new = \"$string\"";
will work, but is insecure if you do not know where $string came
from (imagine the string "\";system(q(rm -rf /));\"" ).
Almost certainly,
s/\$(\w+)/${$1}/g;
is simpler and more secure, but will not work if the variable is a
"my" variable.
s/\$(\w+)/"\$$1"/eg;
solves most of the security problems and works for "my" variables,
but is slow (eval vs indirect variable reference).
Keep in mind that you may only want to have certain variables from
your script disclosed (especially if the program is a CGI script).
This may lead you to use the more restrictive:
s/\$(var|other_var|var_you_can_use)/.../g;
--
Aaron Sherman "We are, all of us, living in the shadow of
Safety Net Solutions Manhatten." -The Watchmen
Email: ajs@ajs.com
WWW: http://ajs.com/~ajs/
------------------------------
Date: Tue, 22 Apr 1997 13:25:57 +0100
From: Ben Hanson <benh@cristie.co.uk>
Subject: Re: Lisp is neither (was Re: Ousterhout and Tcl lost the plot)
Message-Id: <335CAE55.7FE@cristie.co.uk>
John Ousterhout wrote:
<SNIP>
> This reinforces my claim that you should use different tools for different
> tasks. This is also why I didn't mention Lisp in the paper. The things I
> discussed in the white paper aren't the things that Lisp was designed for
> or that it does best, so it isn't really fair to compare Lisp along those
> dimensions.
Lots of Irritating Spurious Parenthesis!
Ben
------------------------------
Date: Tue, 22 Apr 1997 12:10:37 +0100
From: Graham Barr <gbarr@ti.com>
Subject: Re: Module naming question: Net::Rcmd?
Message-Id: <335C9CAD.371@ti.com>
Pete Williams wrote:
> I'm finishing up a module interface to rcmd(3n) and friends. I think the
> natural thing to do is call it Net::Rcmd...
>
> Any comments on this by those who know, before I upload it to CPAN?
Net::Rcmd is probably a good name. Upload it to CPAN so that
other can see what you have done. I have seen mail about this
topic before so I am sure you will get a few questions on the
API.
--
Graham Barr <gbarr@ti.com>
If at first you don't succeed, try again. Then quit. No use being a
damn fool about it.
--Dilbert's Laws
------------------------------
Date: 22 Apr 1997 08:31:13 GMT
From: bmarker@cco.caltech.edu (Bradley J. Marker)
Subject: Re: Name that OS(unix,nt,?) question.
Message-Id: <5jht0h$g74@gap.cco.caltech.edu>
Two ideas:
1. Check the %ENV data. Some of those are NT specific. Choose one. How about
"OS" or "COMSPEC" or some of the others?
2. More general Win32. Write a file in caps. Check for it in lower case. If
PERL says it still exists, you probaly are in NT or Win95. Some UNIX varieties
may not be case sensitive but I can't think of any off the top of my head.
Bradley J. Marker
In article <5jhk3e$ru6$1@comet2.magicnet.net>, mcdowell@magicnet.net (cssm.com)
writes:
>
>How can one tell what Platform a perl script is being run on. I've seen
>PERL scripts that check system files to see if a box is system V or
>BSD, but I also have to deal w/ Windows NT as well.
>
>Curious..
>
>-Patrick.
>patrick.mcdowell@tivoli.com
>
>
------------------------------
Date: 22 Apr 1997 09:43:04 GMT
From: mbeattie@sable.ox.ac.uk (Malcolm Beattie)
Subject: Re: Perl as its own metalanguage?
Message-Id: <5ji178$arq@news.ox.ac.uk>
In article <335BA4C2.6DF60FCD@enteract.com>, Eryq <eryq@enteract.com> wrote:
>As for a Perl program examining itself: apart from looking at the
>symbol table, you don't often see this done. At least, I can't
>think of any program I've ever seen that looks at its own bytecode.
I suppose it's really a module rather than a program but the Perl
compiler makes a program examine itself and look at its own
bytecode (well, op tree). It just loads up the program, pores over
its own entrails and dumps them out in some appropriate format.
The B module provides the necessary XSUBs to examine the internal
structures of the program; the compiler itself is written in Perl.
--Malcolm
--
Malcolm Beattie <mbeattie@sable.ox.ac.uk>
Oxford University Computing Services
"Widget. It's got a widget. A lovely widget. A widget it has got." --Jack Dee
------------------------------
Date: Tue, 22 Apr 1997 10:21:38 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: perl mkdir produces weird permissions
Message-Id: <adelton.861704498@aisa.fi.muni.cz>
Ken Anderson <anderson@necsys.gsfc.nasa.gov> writes:
> Hi again,
>
> i was trying to use the perl mkdir function and
> am winding up with weird permissions on the directory.
>
> mkdir filename,mode
>
> Camel book says that it will be made "with permissions
> set by mode (as modified by the current masks)."
>
> Well, this is rather vague and the behaviour is not
> at all obvious. eg.
>
> on a process with the umask as 022
>
> mkdir filex,777 gives d-----x--x filex
>
> mkdir filex,000 gives d--------- filex
>
> mkdir filex,333 gives dr-x--xr-x filex
>
> mkdir filex,111 gives d--xr-xr-x filex
>
> mkdir filex,755 gives d-wxr----x filex
>
>
> does this make sense to anybody?
It will be pretty clear, once you convert your decimal numbers into
octal ones.
Hope this helps.
--
------------------------------------------------------------------------
Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
I can take or leave it if I please
------------------------------------------------------------------------
------------------------------
Date: Tue, 22 Apr 1997 12:00:07 +0100
From: Alastair Aitken <a.aitken@unl.ac.uk>
Subject: Re: perl mkdir produces weird permissions
Message-Id: <335C9A37.D97EF5AA@unl.ac.uk>
Ken Anderson wrote:
> mkdir filex,777 gives d-----x--x filex
>
> mkdir filex,000 gives d--------- filex
>
> mkdir filex,333 gives dr-x--xr-x filex
>
> mkdir filex,111 gives d--xr-xr-x filex
>
> mkdir filex,755 gives d-wxr----x filex
>
> does this make sense to anybody?
Use the four digit mode setting:
mkdir filea,0666 gives drw-rw-rw-
mkdir fileb,6777 gives drwsrwsrwx
mkdir filec,4755 gives drwsr-xr-x
Same with dbmopen() - always use the four digit mode settings.
Alastair.
------------------------------
Date: 22 Apr 1997 12:06:47 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: perl mkdir produces weird permissions
Message-Id: <5ji9kn$mcm$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
Alastair Aitken <a.aitken@unl.ac.uk> writes:
:Use the four digit mode setting:
:
:mkdir filea,0666 gives drw-rw-rw-
:mkdir fileb,6777 gives drwsrwsrwx
:mkdir filec,4755 gives drwsr-xr-x
:
:Same with dbmopen() - always use the four digit mode settings.
No -- you don't need four digits -- you need a leading
0. For example, you want 04755 not 4755. Otherwise
it's not octal.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
In English, every word can be verbed. Would that it were so in our
programming languages.
------------------------------
Date: Tue, 15 Apr 1997 14:28:39 GMT
From: Chris_Houck@i2.com
Subject: Perl profiler
Message-Id: <E8oo7x.2Bz@i2.COM>
Is there a profiling tool for Perl?
------------------------------
Date: 22 Apr 1997 14:25:23 +0100
From: Olivier Dehon <dehon_olivier@jpmorgan.com>
Subject: Re: Perl profiler
Message-Id: <njz2083b35o.fsf@jpmorgan.com>
Chris_Houck@i2.com writes:
>
> Is there a profiling tool for Perl?
Check Devel::Dprof at the CPAN.
Hope this helps.
Olivier Dehon.
------------------------------
Date: 21 Apr 1997 14:19:03 GMT
From: "Harry Kas" <harry@bci.se>
Subject: Q: How to sort an array of arrays
Message-Id: <01bc4e5e$a22d4760$a20464c3@bci>
Can somebody tell me if it is possible to use the sort function on an array
of arrays?
I have an array[0][1] and want to sort on the first array.
"@array2 = sort @array" is not working. How should I do?
Grateful for any help.
--
Harry Kas - BCi Sweden
tel +46-8-540 650 60
fax +46-8-540 69318
harry@bci.se
------------------------------
Date: Tue, 22 Apr 1997 02:52:30 -0700 (PDT)
From: <Sly@yournamehere.com>
Subject: Reading this will take seconds!
Message-Id: <199704220952.CAA24708@web1.zzz.com>
Thanks for your time. We at I.S.P.O.T. (The International Society
for the Preservation Of Trees (URL http://www.local-touch.com/ISPOT/)) feel
that electronic messages are great for getting the word out while preserving
our friend the tree. Anyway, please stop by our home page!
Thanks again!
Sly
------------------------------
Date: Tue, 22 Apr 1997 11:54:14 +0100
From: Alastair Aitken <a.aitken@unl.ac.uk>
Subject: Re: Regular expression question
Message-Id: <335C98D6.E5BA624D@unl.ac.uk>
Bill Wenger wrote:
> I have data in a comma delimited file such that some of the fields
> themselves contain commas. What I need to do is split the fields by
> the
> commas but the data that has a comma embedded in it is throwing off
> the
> split function. When the data does indeed have a comma in it, the
> data is
> put in double quotes. Thus I have something like the following:
>
> 10,"Fred, Wilma and Pebbles","The Flintstones",100
> 20,"Barney, Betty and Bambam Rubble","The Flintsones",150
> 30,"Jerry Seinfeld","Seinfeld",200
>
> What I would like to be able to do is to break the fields of each
> record
> into 4 fields something like ($f1,$f2,$f3,$f4) = split/,/;
>
> This works on the last record but not on the first two. I don't
> mind
> stripping the extra commas out or replacing them with some other
> character.
#! /usr/local/bin/perl
# This routine accepts three parameters: a CSV file (as a name), a new
file name for output
# and a new field separator character
require 5.003;
use Strict;
my ($infile, $outfile, $sep, @records, $record);
print "Enter full path to CSV file name: ";
$infile = <STDIN>;
print "Enter full path to output file name: ";
$outfile = <STDIN>;
print "Enter a new separator character: ";
$sep = <STDIN>;
if (length($sep) > 1) {
print "Enter a (single) new separator character: ";
$sep = <STDIN>;
}
open (IN, "$file");
@records = <IN>;
close (IN);
open (OUT, "> $file");
foreach $record (@records) {
$record =~ s/",\s*"/"$sep"/s; # occurences of
",\s(any)"
$record =~ s/(\d),\s*"/$1$sep"/s; # occurences of
<digit>,\s(any)"
$record =~ s/(\d),\s*(\d)/$1$sep$2/s; # occurences of
<digit>,\s(any)<digit>
print OUT "$record\n";
}
close (OUT);
exit 0;
This should work on most simple CSV files. It isn't tested but it won't
damage your original CSV file.
Alastair.
------------------------------
Date: 22 Apr 1997 11:24:25 GMT
From: JYoungman@vggas.com (James Youngman)
Subject: Re: Unix and ease of use (WAS: Who makes more ...)
Message-Id: <5ji759$4u6$2@halon.vggas.com>
In article <5j8spp$gg5$1@earth.execpc.com>, madings@earth.execpc.com says...
>Every such script I have seen assumed you had /bin/bash, /bin/ksh,
>or /bin/csh.
>
>For it to be a standard Unix system, you can only assume /bin/sh.
>(Which really sucks by today's standards). While such archives
>might exist, I have not seen them.
I've even seen shar archives of binary files that don't require uudecode. They
unpack and compile their own it required. I was impressed.
--
James Youngman VG Gas Analysis Systems The trouble with the rat-race
Before sending advertising material, read is, even if you win, you're
http://www.law.cornell.edu/uscode/47/227.html still a rat.
------------------------------
Date: 22 Apr 1997 11:28:54 GMT
From: JYoungman@vggas.com (James Youngman)
Subject: Re: Unix and ease of use (WAS: Who makes more ...)
Message-Id: <5ji7dm$4u6$3@halon.vggas.com>
In article <335b4f73.10578287@news.iol.ie>, jab@iol.ie says...
>Seeing as the original subject refers to ease of use, can I just say
>that all the above are inferior as tools in comparison to ZipFolders,
>which allows me to use the .zip archive as *just another directory*.
>It makes use of such archives completely transparent, and lets me use
>any file stored in the archive in the same way as "ordinary" files.
FWIW Emacs has this functionality. It will let you look inside compressed tar
files or ZIP files, just like directories, and even modify things inside and
save the result back to the archive.
--
James Youngman VG Gas Analysis Systems The trouble with the rat-race
Before sending advertising material, read is, even if you win, you're
http://www.law.cornell.edu/uscode/47/227.html still a rat.
------------------------------
Date: Tue, 22 Apr 1997 14:11:24 +0200
From: Kai Ruediger Schobbert <kischobb@immd9.informatik.uni-erlangen.de>
Subject: Re: Who will win? Borland or Microsoft or Programmers?
Message-Id: <335CAAEC.59E2@immd9.informatik.uni-erlangen.de>
M A<34110s96@student.csi.cuny.edu> wrote:
>
> Hi,
> My company is planning to start a project. We have a big question
> about our investments. We don't know if we should use Microsoft
> compiler or Borland. Some myth we heard over the net.
>
> 1) 90% of the programmer uses Microsoft Compiler.
> 2) Borland will vanish in 2 years (NASDAQ:BORL)
> 3) Borland has better compiler
> 4) 99% of the College in US have/use Borland Compiler.
>
> Some one show us the way?
>
> I myself use Borland Compiler and haven't thought about Microsoft yet!
Seems to be a student from "The City University of New York !
(34110s96@student.csi.cuny.edu ??)
Could it be, that it was just intended to start a useless discussion ?
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 342
*************************************