[30670] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1915 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 10 21:09:43 2008

Date: Fri, 10 Oct 2008 18:09:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 10 Oct 2008     Volume: 11 Number: 1915

Today's topics:
    Re: "\!" appears on new line <someone@example.com>
    Re: "\!" appears on new line sln@netherlands.com
    Re: data file <jurgenex@hotmail.com>
    Re: data file <hirenshah.05@gmail.com>
    Re: data file sln@netherlands.com
    Re: data file sln@netherlands.com
    Re: data file xhoster@gmail.com
    Re: data file xhoster@gmail.com
    Re: data file <jurgenex@hotmail.com>
    Re: data file <tadmc@seesig.invalid>
        how to use system call within a cgi script <ktrchang@gmail.com>
    Re: how to use system call within a cgi script <jurgenex@hotmail.com>
    Re: how to use system call within a cgi script <smallpond@juno.com>
    Re: how to use system call within a cgi script (Jamie)
    Re: how to use system call within a cgi script <ktrchang@gmail.com>
    Re: Loading the shell environment? (Jamie)
    Re: Parsing CSV and "&nbsp;&nbsp;" <stpra123@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Fri, 10 Oct 2008 12:31:34 -0700
From: "John W. Krahn" <someone@example.com>
Subject: Re: "\!" appears on new line
Message-Id: <m4OHk.17186$0p.7842@newsfe04.iad>

April wrote:
> this is more concise:
> 
> print "Enter a phrase and convert the first letter to upper case and
> add a ! at end: ";
> chomp( my $input = <STDIN> );
> print ucfirst( $input ), "\!", "\n";

TIMTOWTDI:

print "Enter a phrase and convert the first letter to upper case and add 
a ! at end: ";
( my $input = <STDIN> ) =~ s/$/!/;
print "\u$input";



John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall


------------------------------

Date: Fri, 10 Oct 2008 19:54:55 GMT
From: sln@netherlands.com
Subject: Re: "\!" appears on new line
Message-Id: <oncve4trs5ts18gtf6gcsdgm9sf1bmpesq@4ax.com>

On Fri, 10 Oct 2008 12:31:34 -0700, "John W. Krahn" <someone@example.com> wrote:

>April wrote:
>> this is more concise:
>> 
>> print "Enter a phrase and convert the first letter to upper case and
>> add a ! at end: ";
>> chomp( my $input = <STDIN> );
>> print ucfirst( $input ), "\!", "\n";
>
>TIMTOWTDI:
>
>print "Enter a phrase and convert the first letter to upper case and add 
>a ! at end: ";
>( my $input = <STDIN> ) =~ s/$/!/;
>print "\u$input";
>
>
>
>John

Whoa, this is a wild weazle..

sln



------------------------------

Date: Fri, 10 Oct 2008 11:31:56 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: data file
Message-Id: <bo7ve496flpigi99198d8pe0rv89nda6hd@4ax.com>

"friend.05@gmail.com" <hirenshah.05@gmail.com> wrote:
>> jue- Hide quoted text -
>>
>> - Show quoted text -

What is this "Hide quoted text - Show quoted text" nonsense?

>IF I use
>
>$idtable{"$ip|$code"}++; #record this ip-code combination
>
>will this not replace previous valuse if same key(ip-code) comes
>again ?

Of course it does, that is the whole purpose. Or how do you suggest to
count the number of occurences if not by replacing the previous number
with the new number?

jue


------------------------------

Date: Fri, 10 Oct 2008 11:59:34 -0700 (PDT)
From: "friend.05@gmail.com" <hirenshah.05@gmail.com>
Subject: Re: data file
Message-Id: <6b3f1e32-b9da-47bc-a869-21f8fe8f52b9@h2g2000hsg.googlegroups.com>

On Oct 10, 2:31=A0pm, J=FCrgen Exner <jurge...@hotmail.com> wrote:
> "friend...@gmail.com" <hirenshah...@gmail.com> wrote:
> >> jue- Hide quoted text -
>
> >> - Show quoted text -
>
> What is this "Hide quoted text - Show quoted text" nonsense?
>
> >IF I use
>
> >$idtable{"$ip|$code"}++; #record this ip-code combination
>
> >will this not replace previous valuse if same key(ip-code) comes
> >again ?
>
> Of course it does, that is the whole purpose. Or how do you suggest to
> count the number of occurences if not by replacing the previous number
> with the new number?
>
> jue

Got it thanks.

Sorry abt hide quoted text. I also don't knw wht is tht by mistake I
must click it while replying


------------------------------

Date: Fri, 10 Oct 2008 19:14:00 GMT
From: sln@netherlands.com
Subject: Re: data file
Message-Id: <qf9ve4pl4cc64n5rd7budr6b8koenikcum@4ax.com>

On Fri, 10 Oct 2008 10:55:22 -0700 (PDT), "friend.05@gmail.com" <hirenshah.05@gmail.com> wrote:

>On Oct 10, 12:18 pm, Jürgen Exner <jurge...@hotmail.com> wrote:
>> "friend...@gmail.com" <hirenshah...@gmail.com> wrote:
>> >On Oct 9, 6:08 pm, Ben Morrow <b...@morrow.me.uk> wrote:
>> >> Quoth "friend...@gmail.com" <hirenshah...@gmail.com>:
>>
>> >> > I have a large file in following format:
>>
>> >> > ID | Time | IP | Code
>>
>> >> > I want only data lines which has unique IP+Code.
>>
>> >> > If IP+Code is repeated then I don't want line.
>>
>> >Below is code which I have written to extract unique IP+Code from
>> >large file. (File format is ID | Time | IP | code).
>>
>> >I am not sure which will be best way to do this.
>>
>> >#!/usr/local/bin/perl
>> >$pri_file = "out_pri.txt";
>>
>> >$cnt = 0;
>> >$flag = 0;
>>
>> >open(INFO_PRI,$pri_file)or die $!;
>> >open(INFO,$pri_file)or die $!;
>>
>> >@pri_lines_ = <INFO>;
>>
>> >while($pri_line = <INFO_PRI>)
>>
>> [rest of code snipped]
>>
>> Many things I don't understand in this code, among them why you are
>> using 2 file handles to the same file, why you are slurping in the whole
>> file on one file handle and then process the file line by line on the
>> other file handle, why you have a nested loop, etc, etc.
>>
>> Your requirements seem to be straight forward and easy to translate into
>> a simple algorithm (warning, sketch only, not tested):
>>
>> my %idtable;
>> open ($F, '<', $myfile) of die "Cannot read $myfile because $!\n";
>> while (<$F>) { #loop through file and gather all IP | Code combinations
>>         (undef, undef, $ip, $code) = split '\|';
>>         $idtable{"$ip|$code"}++; #record this ip-code combination}
>>
>> seek $F, 0; #reset file to start
>> while (<$F>) { #loop through file again and ....
>>         (undef, undef, $ip, $code) = split '\|';
>>         print if $idtable{"$ip|$code"} == 1;
>>                 #... print that line if the ip-code combination
>>                 #exists exactly once in the file
>> close $F;
>>
>> jue- Hide quoted text -
>>
>> - Show quoted text -
>
>Hi jue,
>
>IF I use
>
>$idtable{"$ip|$code"}++; #record this ip-code combination
>
>will this not replace previous valuse if same key(ip-code) comes
>again ?

This may not have been clear....

"$idtable{"$ip|$code"}", in this case is just a variable used as
a counter. Its no different than incrementing any other counter,
like $cnt++

In that respect, it just uses the IP and Code as a concantinated
string as a key into a hash array. Where the key contains the
encoded data.

In my opinion, this is not the way to go. If there is only a few IP
and many many Code, this could create an inordinantly large hash,
resulting in long lookup times.

You could double your money by getting unique IP, as well as shortening the
cpu overhead if you do it this way:

$idtable{$ip}->{$code}++

There is a tradeoff. Don't know really. Depends on the prediction if the amount of unique
Codes outnumbers the amount of IPs ... or something like that.

sln




------------------------------

Date: Fri, 10 Oct 2008 19:51:24 GMT
From: sln@netherlands.com
Subject: Re: data file
Message-Id: <c7cve4l9lu5dc1gknjo4nmpmagrc4lof96@4ax.com>

On Fri, 10 Oct 2008 12:49:22 -0500, "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid> wrote:

>Jürgen Exner wrote:
>> "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid> wrote:
>>> friend.05@gmail.com wrote:
>>>> On Oct 9, 6:08 pm, Ben Morrow <b...@morrow.me.uk> wrote:
>>>>> Quoth "friend...@gmail.com" <hirenshah...@gmail.com>:
>>>>>
>>>>>> I have a large file in following format:
>>>>>> ID | Time | IP | Code
>>>>>> I want only data lines which has unique IP+Code.
>>>>>> If IP+Code is repeated then I don't want line.
>>>>> perldoc -q unique
>>>>>
>>>>> Ben
>>>> Below is code which I have written to extract unique IP+Code from
>>>> large file. (File format is ID | Time | IP | code).
>>>>
>>>> I am not sure which will be best way to do this.
>>> Well, it's not the way you posted.
>>>
>>> Did you actually read the perldoc Ben mentioned above?  You don't use a 
>>> hash at all, so I'm guessing not.
>> 
>> ACK!
>> 
>>> while ( my $line = <$INFO> )
>>> {
>>> 	chomp( $line );
>>> # split the data.. you can split directly into the variables..
>>> # my ( $v1, $v2 ) = ( split( /\|/, $line ) )[1,2];
>>> # print $line to $OUT if the hash key of $cli_ip and $id doesn't already 
>>> exist.
>> 
>> That will print each IP+code exactly once. I think (but I may be
>> mistaken, the OPs isn't clear on that) he wants only those lines, that
>> _are_ unique wrt. the IP+code, i.e. where there is no second line with
>> the same IP+code.
>
>You're right, I mis-understood.
>
>A fairly easy to follow solution would be to keep track of the data, 
>using two hashes.
>
>my (%times, %line );
>
>while(...)
>{
>	# chomp,split,...
>	# times is the number of times the $cli_ip and $id were found
>	$times{ $cli_ip . $id }++;
>	# could 'next' if it is > 1
>	# and store the line itself, for the $cli_ip and $id
>	$line{ $cli_ip . $id } = $line;
>}
>
>Then, after the while, for each of the keys in %times, print the
>value from %line where the value of $times{ $key } is 1, to the output file.
>
>That should be enough to get the OP in the right direction, without
>writing the whole darn thing for them.

Doesen't this overwrite whats already there? Not sure.
$line{ $cli_ip . $id } = $line;

sln



------------------------------

Date: 10 Oct 2008 20:20:31 GMT
From: xhoster@gmail.com
Subject: Re: data file
Message-Id: <20081010162034.174$rm@newsreader.com>

sln@netherlands.com wrote:
> On Fri, 10 Oct 2008 12:49:22 -0500, "J. Gleixner"
> <glex_no-spam@qwest-spam-no.invalid> wrote:
> >
> >A fairly easy to follow solution would be to keep track of the data,
> >using two hashes.
> >
> >my (%times, %line );
> >
> >while(...)
> >{
> >       # chomp,split,...
> >       # times is the number of times the $cli_ip and $id were found
> >       $times{ $cli_ip . $id }++;
> >       # could 'next' if it is > 1
> >       # and store the line itself, for the $cli_ip and $id
> >       $line{ $cli_ip . $id } = $line;
> >}
> >
> >Then, after the while, for each of the keys in %times, print the
> >value from %line where the value of $times{ $key } is 1, to the output
> >file.
> >
> >That should be enough to get the OP in the right direction, without
> >writing the whole darn thing for them.
>
> Doesen't this overwrite whats already there? Not sure.
> $line{ $cli_ip . $id } = $line;

Yes, of course.  But since those lines won't get printed anyway (because
count > 1) then it doesn't matter if they get overwritten.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


------------------------------

Date: 10 Oct 2008 20:26:32 GMT
From: xhoster@gmail.com
Subject: Re: data file
Message-Id: <20081010162635.263$Yh@newsreader.com>

"J. Gleixner" <glex_no-spam@qwest-spam-no.invalid> wrote:
> >
> > That will print each IP+code exactly once. I think (but I may be
> > mistaken, the OPs isn't clear on that) he wants only those lines, that
> > _are_ unique wrt. the IP+code, i.e. where there is no second line with
> > the same IP+code.
>
> You're right, I mis-understood.
>
> A fairly easy to follow solution would be to keep track of the data,
> using two hashes.
>
> my (%times, %line );
>
> while(...)
> {
>         # chomp,split,...
>         # times is the number of times the $cli_ip and $id were found
>         $times{ $cli_ip . $id }++;
>         # could 'next' if it is > 1
>         # and store the line itself, for the $cli_ip and $id
>         $line{ $cli_ip . $id } = $line;
> }

I might go with just a single hash, using undef as a special value to
indicate we already have seen more than one.

my %line;

while(...)
{
        # chomp,split,...
        if (exists $line{ $cli_ip . $id }) {
           $line{ $cli_ip . $id } = undef;   #skunked
        } else {
           $line{ $cli_ip . $id } = $line;
        };
}



>
> Then, after the while, for each of the keys in %times, print the
> value from %line where the value of $times{ $key } is 1, to the output
> file.

Under my method, print the things from %line where the value is defined.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


------------------------------

Date: Fri, 10 Oct 2008 13:44:53 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: data file
Message-Id: <eafve4dgbfk8kb8h7qh2ssnedppdf0hjcj@4ax.com>

"J. Gleixner" <glex_no-spam@qwest-spam-no.invalid> wrote:
>	$times{ $cli_ip . $id }++;

Careful! This may give wrong results in odd circumstances. 
Example:
	$cli_ip='foobar', $id='buz';
and
	$cli_ip='foo', $id='barbuz';
	
Better to use the same separator as in the original data set, regardless
of  if such a scenario may or may not happen with the OPs data set:

	$times{ $cli_ip . '|' . $id }++;

jue


------------------------------

Date: Fri, 10 Oct 2008 15:37:28 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: data file
Message-Id: <slrngevf88.q1v.tadmc@tadmc30.sbcglobal.net>

friend.05@gmail.com <hirenshah.05@gmail.com> wrote:

> Sorry abt hide quoted text. I also don't knw wht is tht by mistake I
        ^^^                                ^^^ ^^^    ^^^
        ^^^                                ^^^ ^^^    ^^^

Vanna, I would like to buy a vowel!


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


------------------------------

Date: Fri, 10 Oct 2008 13:41:11 -0700 (PDT)
From: ReggieC <ktrchang@gmail.com>
Subject: how to use system call within a cgi script
Message-Id: <116bd205-830c-47ce-8605-731d6340b1d5@x16g2000prn.googlegroups.com>

Hi there,

I have to execute an executable from a CGI script written in perl.  I
cannot do that even
with a very simple test like:
$result = system("mkdir test1");
$result = system("mkdir ", "test1");
exec('mkdir test1');
but always got 500 Internal Service Error.

Adding $ENV{"PATH"} = ""; and use full path of mkdir did not help.

I'm using perl 5.8 with Apache 2.2.

Any opinion is very much appreciated.


------------------------------

Date: Fri, 10 Oct 2008 13:54:25 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: how to use system call within a cgi script
Message-Id: <k2gve49meltnhm8gj08b0rhed7p0lncqap@4ax.com>

ReggieC <ktrchang@gmail.com> wrote:
>Hi there,
>
>I have to execute an executable from a CGI script written in perl.  I
>cannot do that even
>with a very simple test like:
>$result = system("mkdir test1");
>$result = system("mkdir ", "test1");
>exec('mkdir test1');
>but always got 500 Internal Service Error.

What does the server log tell you?

>Adding $ENV{"PATH"} = ""; and use full path of mkdir did not help.
>I'm using perl 5.8 with Apache 2.2.
>Any opinion is very much appreciated.

Could be many, many, many things. Missing permissions, wrong path,
virtual root folder, ...

See 'perldoc -q 500' for some ideas.

jue


------------------------------

Date: Fri, 10 Oct 2008 13:57:09 -0700 (PDT)
From: smallpond <smallpond@juno.com>
Subject: Re: how to use system call within a cgi script
Message-Id: <a96ee038-8974-4969-b0bc-3c8d02aef97c@64g2000hsm.googlegroups.com>

On Oct 10, 4:41 pm, ReggieC <ktrch...@gmail.com> wrote:
> Hi there,
>
> I have to execute an executable from a CGI script written in perl.  I
> cannot do that even
> with a very simple test like:
> $result = system("mkdir test1");
> $result = system("mkdir ", "test1");
> exec('mkdir test1');
> but always got 500 Internal Service Error.
>
> Adding $ENV{"PATH"} = ""; and use full path of mkdir did not help.
>
> I'm using perl 5.8 with Apache 2.2.
>
> Any opinion is very much appreciated.

What is the permission and owner on the directory where you are
trying
to make a new subdirectory and what user are you running as?



------------------------------

Date: Fri, 10 Oct 2008 21:39:29 GMT
From: nospam@geniegate.com (Jamie)
Subject: Re: how to use system call within a cgi script
Message-Id: <Lc122367511847720x191a9c0@saturn>

In <116bd205-830c-47ce-8605-731d6340b1d5@x16g2000prn.googlegroups.com>,
ReggieC <ktrchang@gmail.com> mentions:
>Hi there,
>
>I have to execute an executable from a CGI script written in perl.  I
>cannot do that even
>with a very simple test like:
>$result = system("mkdir test1");
>$result = system("mkdir ", "test1");
>exec('mkdir test1');
>but always got 500 Internal Service Error.
>
>Adding $ENV{"PATH"} = ""; and use full path of mkdir did not help.
>
>I'm using perl 5.8 with Apache 2.2.
>
>Any opinion is very much appreciated.

Print out a header first so you can see the problem? Also, try redirecting
stderr to see any error messages.

In "production", I often use system in a list context:

system('/bin/mkdir','path1');

You probably don't want it evaluated by the shell.

Most likely it's a permissions issue.

Jamie
-- 
http://www.geniegate.com                    Custom web programming
Perl * Java * UNIX                        User Management Solutions


------------------------------

Date: Fri, 10 Oct 2008 15:46:59 -0700 (PDT)
From: ReggieC <ktrchang@gmail.com>
Subject: Re: how to use system call within a cgi script
Message-Id: <6ec8457d-42c0-4ca5-86db-823bdfe175c3@v39g2000pro.googlegroups.com>

Thanks for info from Jue and Smallpond.

Basically the key is $ENV{"PATH"}="";

After I carefully checked, I missed to declare my $result after
adding $ENV{"PATH"}="";  (I modified and moved lined around
while testing.   When I did not have $ENV{"PATH"}="";  I did
have my $result.)

Thanks a lot for the tip of checking logs.  The info there tipped
me up.    Knowing perldoc -q 500 is useful, too.

Thanks again.


smallpond wrote:
> On Oct 10, 4:41 pm, ReggieC <ktrch...@gmail.com> wrote:
> > Hi there,
> >
> > I have to execute an executable from a CGI script written in perl.  I
> > cannot do that even
> > with a very simple test like:
> > $result = system("mkdir test1");
> > $result = system("mkdir ", "test1");
> > exec('mkdir test1');
> > but always got 500 Internal Service Error.
> >
> > Adding $ENV{"PATH"} = ""; and use full path of mkdir did not help.
> >
> > I'm using perl 5.8 with Apache 2.2.
> >
> > Any opinion is very much appreciated.
>
> What is the permission and owner on the directory where you are
> trying
> to make a new subdirectory and what user are you running as?


------------------------------

Date: Fri, 10 Oct 2008 21:51:59 GMT
From: nospam@geniegate.com (Jamie)
Subject: Re: Loading the shell environment?
Message-Id: <Lc122367544447720x19507e0@saturn>

In <bac5321a-9817-4f3a-8911-88098cdb0706@h60g2000hsg.googlegroups.com>,
T <g4173c@motorola.com> mentions:
>Greetings:
>
>    We use Modules ( I hate that they chose that name) to load our
>shell environment here. So I can do:
>
>    mod load myproject
>
>   "mod" is an alias to:
>
>/cae/Modules/${MODULE_VERSION}/bin/modulecmd bash load hagrid

And you need the environment from the child shell?

UNIX doesn't work that way, each child process inherits the environment from
the parent. A child process can't change the environment of the parent. (this
is why "cd" is a shell built in) Believe it or not, this is a feature of unix.
(just imagine if a child process could change your path so that the 'cp'
command is now the 'rm' command!)

When you "source" a shell script, you're just telling the shell to run the 
script in the current process. 

If you're using linux, you can get the environment in a highly non-portable way
using the "proc" filesystem.

To see it try this:

    cat /proc/$PID/environ | tr "\0" "\n" 

(You need permission..) Of course, the process needs to be running for it 
to work...

This isn't portable at all!

Probably your best bet is to have a shell wrapper emit the environment to 
stdout and parse the results in perl.


Jamie
-- 
http://www.geniegate.com                    Custom web programming
Perl * Java * UNIX                        User Management Solutions


------------------------------

Date: Fri, 10 Oct 2008 17:33:21 -0700 (PDT)
From: hotkitty <stpra123@gmail.com>
Subject: Re: Parsing CSV and "&nbsp;&nbsp;"
Message-Id: <9db04034-99fc-408d-9b33-6c1fe873d835@k30g2000hse.googlegroups.com>

On Oct 9, 3:11=A0pm, s...@netherlands.com wrote:
> On Thu, 09 Oct 2008 18:52:50 GMT, s...@netherlands.com wrote:
> >On Wed, 8 Oct 2008 16:58:03 -0700 (PDT), hotkitty <stpra...@gmail.com> w=
rote:
>
> >>I'm trying to parse the following csv file in a linux environment:
>
> >>"this is row1 column0","this is row1 column1","this is row1
> >>column2","this is row1 column3","this
> >>is row1 column4"
> >>"this is row2 column0","this is row2 column1","this is row2
> >>column2","this is row2 column3","this is
> >>row2 column4"
>
> >>Pretty standard CSV but with the last column running onto the next
> >>line it gets screwed up somehow as my script doesn't recognize when a
> >>new row starts. I tried substituting the carriage return but still no
> >>luck. When I open up the file on my windows box w/ notepad I get the
> >>following (notice the " &nbsp;&nbsp;" that is added to the end of the
> >>line):
> >>"this is row1 column0","this is row1 column1","this is row1
> >>column2","this is row1 column3","this
> >>is row1 column4"" &nbsp;&nbsp;"
> >>"this is row2 column0","this is row2 column1","this is row2
> >>column2","this is row2 column3","this is
> >>row2 column4"" &nbsp;&nbsp;"
>
> >>Maybe I'm just overlooking some simple solution but how do I deal w/
> >>the " &nbsp;&nbsp;" as Linux doesn't recognize it?
>
> >>Thanks in advance. My code is as follows:
>
> >>my $csv=3D Text::CSV->new(); ####### I've also tried setting binary to =
1
> >>but still didn't work
> >>open (CSV, "<", $thisfile) or die $!;
> >> while (<CSV>) {
> >> =A0 =A0 =A0 =A0if ($csv->parse($_)) {
> >>my @csvcolumns=3D $csv->fields();
> >>my $newstuff =3D "$csvcolumns[1]";
> >>open(OUT, ">>$thatfile");
> >>print OUT "$newstuff\n";
> >>close(OUT);
> >>}
>
> >This is one way. I used the criteria buffer a row until /"$/, eol is fou=
nd,
> >and just process remaining buffer if EOF. Otherwise, there is no delinea=
tion of rows..
>
> >sln
>
> >#############
> ># Csv1 Regex
> >#############
>
> >use strict;
> >use warnings;
>
> >my $fname =3D 'c:\temp\junk.csv';
> >open CSV, $fname or die "can't open $fname...";
>
> >my ($row, $tmp) =3D ('','');
> >my ($parsing, $count) =3D (1,1);
>
> >while ($parsing)
> >{
> > =A0 =A0if (!($_ =3D <CSV>))
> > =A0 =A0{
> > =A0 =A0 =A0 =A0 =A0 =A0$parsing =3D 0;
> > =A0 =A0} else {
> > =A0 =A0 =A0 =A0 =A0 =A0$tmp =3D $_;
> > =A0 =A0 =A0 =A0 =A0 =A0$tmp =3D~ s/\s+$//s;
> > =A0 =A0 =A0 =A0 =A0 =A0$row .=3D " $tmp" if (length($tmp));
> > =A0 =A0 =A0 =A0 =A0 =A0## buffer until '"$' or eof
> > =A0 =A0 =A0 =A0 =A0 =A0next if ($tmp !~ /"$/);
> > =A0 =A0}
> > =A0 =A0print " (".$count++.") ----------\n";
> > =A0 =A0while ($row =3D~ /\s*"+\s*([^"]*?)\s*"+\s*|\s*([^,\n]+)\s*/g)
> > =A0 =A0{
> > =A0 =A0 =A0 =A0 =A0 =A0my $val =3D defined $1 ? $1 : $2;
> > =A0 =A0 =A0 =A0 =A0 =A0print "val =3D $val\n";
> > =A0 =A0 =A0 =A0 =A0 =A0# ... push @ary, $val;
> > =A0 =A0}
> > =A0 =A0$row =3D $tmp =3D '';
> >}
>
> >close CSV;
>
> >__END__
>
> >output:
>
> > (1) ----------
> >val =3D this is row1 column0
> >val =3D this is row1 column1
> >val =3D this is row1 column2
> >val =3D this is row1 column3
> >val =3D this is row1 column4
> > (2) ----------
> >val =3D this is row2 column0
> >val =3D this is row2 column1
> >val =3D this is row2 column2
> >val =3D this is row2 column3
> >val =3D this is row2 column4
> > (3) ----------
> >val =3D this is row3 column0
> >val =3D this is row3 column1
>
> >junk.csv
> >----------
> >"this is row1 column0","this is row1 column1","this is row1
> >column2","this is row1 column3","this
> >is row1 column4"
> >"this is row2 column0","this is row2 column1","this is row2
> >column2","this is row2 column3","this is
> >row2 column4"
>
> >"this is row3 column0","this is row3 column1",
>
> Btw, Excel will not do this correctly. Either you have to generate a
> proper csv file (with EOR definition), or do this kind of a fix-up using =
your own criteria.

I apologize for the late reply but appreciate the quick responses you
have given me. Perhaps I am doing something wrong w/ the above
suggestions but I'll keep cracking away. Here is the actual .csv file
I am trying to parse:
http://www.nasdaq.com//asp/symbols.asp?exchange=3DQ&start=3D0

thx



------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 1915
***************************************


home help back first fref pref prev next nref lref last post