Skip to search.

Breaking News Visit Yahoo! News for the latest.

×Close this window

perl-beginner · Perl Beginners Mailing List

The Yahoo! Groups Product Blog

Check it out!

Group Information

  • Members: 3765
  • Category: Perl
  • Founded: Aug 2, 1998
  • Language: English
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Real people. Real stories. See how Yahoo! Groups impacts members worldwide.

Messages

Advanced
Messages Help
Messages 19336 - 19365 of 27459   Oldest  |  < Older  |  Newer >  |  Newest
Messages: Show Message Summaries Sort by Date ^  
#19336 From: jmostert@...
Date: Sun Aug 1, 2004 10:38 am
Subject: How do I.....?
jm_1983310
Send Email Send Email
 
Dear Group,

   I'm a beginner in PHP and would like to know how
   do I use 'fopen()' to write to files, because of some
   wierd reason I have to set some flag because of a permission
   problem in PHP that does not allow me to "by default" write
   files to my 'httpdocs' directory. I can read files but not
   write to them. This is kinda strange, but yeah.


   Any help would really be appreciated.
   Thanks for your time.



   -Jacques.

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.

#19337 From: "Allan Dystrup" <allan_dystrup@...>
Date: Mon Aug 2, 2004 5:50 pm
Subject: Re: How do I.....?
allan_dystrup
Send Email Send Email
 
http://dk.php.net/fopen

btw,
PHP... is Hardly Perl is Hardly Perl is Hardly Perl
allan dystrup

--- In perl-beginner@yahoogroups.com, jmostert@v... wrote:
> Dear Group,
>
>   I'm a beginner in PHP and would like to know how
>   do I use 'fopen()' to write to files, because of some
>   wierd reason I have to set some flag because of a permission
>   problem in PHP that does not allow me to "by default" write
>   files to my 'httpdocs' directory. I can read files but not
>   write to them. This is kinda strange, but yeah.
>
>
>   Any help would really be appreciated.
>   Thanks for your time.
>
>
>
>   -Jacques.
>
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.

#19338 From: jmostert@...
Date: Mon Aug 2, 2004 7:22 pm
Subject: Re: [PBML] Re: How do I.....?
jm_1983310
Send Email Send Email
 
LOL.

     Uh, yeah.. OK. I GET IT!


Quoting Allan Dystrup <allan_dystrup@...>:
> http://dk.php.net/fopen
>
> btw,
> PHP... is Hardly Perl is Hardly Perl is Hardly Perl
> allan dystrup
>
> --- In perl-beginner@yahoogroups.com, jmostert@v... wrote:
> > Dear Group,
> >
> >   I'm a beginner in PHP and would like to know how
> >   do I use 'fopen()' to write to files, because of some
> >   wierd reason I have to set some flag because of a permission
> >   problem in PHP that does not allow me to "by default" write
> >   files to my 'httpdocs' directory. I can read files but not
> >   write to them. This is kinda strange, but yeah.
> >
> >
> >   Any help would really be appreciated.
> >   Thanks for your time.
> >
> >
> >
> >   -Jacques.
> >
> > ----------------------------------------------------------------
> > This message was sent using IMP, the Internet Messaging Program.
>
>
>
>
> Unsubscribing info is here:
> http://help.yahoo.com/help/us/groups/groups-32.html
> Yahoo! Groups Links
>
>
>
>
>
>




----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.

#19339 From: Paul Archer <tigger@...>
Date: Tue Aug 3, 2004 7:25 pm
Subject: moving files to existing structure
tigger@...
Send Email Send Email
 
I've got a bunch (thousands) of files in a structure like this:

/somedir/traces/2004/08/03/abc/longfilename.abi

and I need to move them to another directory structure that already has some
directories in place:

/data/traces/2004/08/03/abc/longfilename.abi

where /data/traces/2004/08/03 (for example) may or may not exist.


The problem comes in when trying to simply 'mv' the files, as I can't say
mv /somedir/traces /data/traces
because the 'traces' directory already exists.

So the question is: is there a module/script whatever out there that would
help with this? I'd rather not have to write a solution from scratch if I
can avoid it. (It would have to find each filename, check to see if the
directory structure existed already, create it if doesn't, and then move the
file.)

Paul Archer



-------------------------------------------------
"Welcome to downtown Coolsville--population: us."
-------------------------------------------------

#19340 From: merlyn@...
Date: Tue Aug 3, 2004 7:37 pm
Subject: Re: [PBML] moving files to existing structure
merlynstoneh...
Send Email Send Email
 
>>>>> "Paul" == Paul Archer <tigger@...> writes:

Paul> So the question is: is there a module/script whatever out there
Paul> that would help with this? I'd rather not have to write a
Paul> solution from scratch if I can avoid it. (It would have to find
Paul> each filename, check to see if the directory structure existed
Paul> already, create it if doesn't, and then move the file.)

It's about eight lines of code.  If you don't want to write it
from scratch, maybe you can hire someone to write eight lines
of code for you.

perldoc File::Basename (especially basename and dirname)
perldoc -f mkdir
perldoc File::Copy

Truly, you are demonstrating laziness beyond reproach.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

#19341 From: Dave Gray <yargevad@...>
Date: Tue Aug 3, 2004 7:54 pm
Subject: Re: [PBML] moving files to existing structure
yargevad
Send Email Send Email
 
On Tue, 3 Aug 2004 14:25:53 -0500 (CDT), Paul Archer <tigger@...> wrote:
> I've got a bunch (thousands) of files in a structure like this:
>
> /somedir/traces/2004/08/03/abc/longfilename.abi
>
> and I need to move them to another directory structure that already has some
> directories in place:
>
> /data/traces/2004/08/03/abc/longfilename.abi
>
> where /data/traces/2004/08/03 (for example) may or may not exist.

rsync will do what you need (run the following from /somedir/traces):
  rsync -vur . /data/traces

The command-line switches are v=verbose, u=update, r=recursive, which
should be all you need. The manpage has more info if you want to do
some fancier stuff.

There's probably a perl interface to it (I can't access CPAN at the
moment for some reason), but that seems like overkill for this
specific task.

Cheers,
Dave

#19342 From: Paul Archer <tigger@...>
Date: Tue Aug 3, 2004 9:08 pm
Subject: Re: [PBML] moving files to existing structure
tigger@...
Send Email Send Email
 
12:37pm, merlyn@... wrote:

> >>>>> "Paul" == Paul Archer <tigger@...> writes:
>
> Paul> So the question is: is there a module/script whatever out there
> Paul> that would help with this? I'd rather not have to write a
> Paul> solution from scratch if I can avoid it. (It would have to find
> Paul> each filename, check to see if the directory structure existed
> Paul> already, create it if doesn't, and then move the file.)
>
> It's about eight lines of code.  If you don't want to write it
> from scratch, maybe you can hire someone to write eight lines
> of code for you.
>
> perldoc File::Basename (especially basename and dirname)
> perldoc -f mkdir
> perldoc File::Copy
>
> Truly, you are demonstrating laziness beyond reproach.
>

Maybe you misunderstood me.

(Here's the bit you chopped off my original post):
----include----
I've got a bunch (thousands) of files in a structure like this:

/somedir/traces/2004/08/03/abc/longfilename.abi

and I need to move them to another directory structure that already has some
directories in place:

/data/traces/2004/08/03/abc/longfilename.abi

where /data/traces/2004/08/03 (for example) may or may not exist.


The problem comes in when trying to simply 'mv' the files, as I can't say
mv /somedir/traces /data/traces
because the 'traces' directory already exists.
---end include----


I can't simply do a mv (either a Unix mv or a Perl mv/move) because of the
existing structure. I have to preserve the structure from 'traces' on. I
can't simply dump the files into the same directory.
In other words:

mkdir -p /tmp/temp_dir/traces/2004/08/03/
mkdir -p /tmp/final_dir/traces/2004/08/03
touch /tmp/temp_dir/traces/2004/08/03/file_to_be_moved.abi

# doesn't work
mv /tmp/temp_dir/traces /tmp/final_dir

# works, but requires the directory structure to be checked/created
# for every file moved
mv /tmp/temp_dir/traces/2004/08/03/file_to_be_moved.abi \
    /tmp/final_dir/traces/2004/08/03

Checking/creating the directory structure wouldn't be so bad, but I've got
to move over 3.6 million files.

Now, it may be that there's a simple solution. It may be that I'm being lazy
("beyond reproach", even) for asking for help rather than slogging it out
completely on my own (but I don't think so). But I doubt a workable solution
is going to fit in 8 lines of code.


Paul Archer

#19343 From: "Jeff Eggen" <jeggen@...>
Date: Tue Aug 3, 2004 9:23 pm
Subject: Re: [PBML] moving files to existing structure
jeggen@...
Send Email Send Email
 
>>> tigger@... 03/08/2004 3:08:26 pm >>>
>Now, it may be that there's a simple solution. It may be that I'm being lazy
>("beyond reproach", even) for asking for help rather than slogging it out
>completely on my own (but I don't think so). But I doubt a workable solution
>is going to fit in 8 lines of code.

How about 4 lines?

cd /somedir/traces
tar cf /tmp/somefile.tar *
cd /data/traces
tar xf /tmp/somefile.tar

This will overwrite stuff with the same name, but won't hurt anything that
already exists in /data/traces but doesn't in /somedir/traces.

Another solution would be a one-liner with find & cpio, but I can't remember it
off the top of my head.  I think it's something like

find /somedir/traces -print | cpio -dumpV /data/traces

Another way would be to copy stuff with the cp command, and then remove the old
stuff.

Another way would be rsync.

Another way would be, if you don't care about the existing stuff under
/data/traces with name conflicts, then you can just do a

mv /somedir/traces/* /data/traces/

If none of these does what you want, then I must be misunderstanding the
problem, in which case I apologize.  All of these solutions will cause problems
with name conflicts, but that isn't hard to overcome if you have a naming
convention for archiving pre-existing files.

Hope one of these helps,

Jeff Eggen
IT Programmer Analyst
Saskatchewan Government Insurance
Ph (306) 751-1795
email jeggen@...

************DISCLAIMER*************
This e-mail and any files transmitted with it are confidential and intended
solely for the use of the individual or entity to whom they are addressed.  If
you are not the named addressee, please notify the sender immediately by e-mail
if you have received this e-mail by mistake and delete this e-mail from your
system. If you are not the intended recipient you are notified that using,
disclosing, copying or distributing the contents of this information is strictly
prohibited.
************DISCLAIMER*************

#19344 From: Paul Archer <tigger@...>
Date: Tue Aug 3, 2004 9:24 pm
Subject: Re: [PBML] moving files to existing structure
tigger@...
Send Email Send Email
 
3:54pm, Dave Gray wrote:

> On Tue, 3 Aug 2004 14:25:53 -0500 (CDT), Paul Archer <tigger@...> wrote:
> > I've got a bunch (thousands) of files in a structure like this:
> >
> > /somedir/traces/2004/08/03/abc/longfilename.abi
> >
> > and I need to move them to another directory structure that already has some
> > directories in place:
> >
> > /data/traces/2004/08/03/abc/longfilename.abi
> >
> > where /data/traces/2004/08/03 (for example) may or may not exist.
>
> rsync will do what you need (run the following from /somedir/traces):
>  rsync -vur . /data/traces
>
> The command-line switches are v=verbose, u=update, r=recursive, which
> should be all you need. The manpage has more info if you want to do
> some fancier stuff.
>
> There's probably a perl interface to it (I can't access CPAN at the
> moment for some reason), but that seems like overkill for this
> specific task.
>

Thanks for the suggestion. It's close, but unfortunately, I can't copy the
files and then delete the originals (I don't have the space--the files are
about 3/4 of a terabyte total). And I can't see any way to get rsync to
delete a file after it has sync'ed it to the new structure (not surprising,
there).

Thanks anyway,

Paul

#19345 From: Paul Archer <tigger@...>
Date: Tue Aug 3, 2004 9:27 pm
Subject: Re: [PBML] moving files to existing structure
tigger@...
Send Email Send Email
 
3:23pm, Jeff Eggen wrote:

> >>> tigger@... 03/08/2004 3:08:26 pm >>>
> >Now, it may be that there's a simple solution. It may be that I'm being lazy
> >("beyond reproach", even) for asking for help rather than slogging it out
> >completely on my own (but I don't think so). But I doubt a workable solution
> >is going to fit in 8 lines of code.
>
> How about 4 lines?
>
> cd /somedir/traces
> tar cf /tmp/somefile.tar *
> cd /data/traces
> tar xf /tmp/somefile.tar
>
> This will overwrite stuff with the same name, but won't hurt anything that
already exists in /data/traces but doesn't in /somedir/traces.
>
> Another solution would be a one-liner with find & cpio, but I can't remember
it off the top of my head.  I think it's something like
>
> find /somedir/traces -print | cpio -dumpV /data/traces
>
> Another way would be to copy stuff with the cp command, and then remove the
old stuff.
>
> Another way would be rsync.
>
> Another way would be, if you don't care about the existing stuff under
/data/traces with name conflicts, then you can just do a
>
> mv /somedir/traces/* /data/traces/
>
> If none of these does what you want, then I must be misunderstanding the
problem, in which case I apologize.  All of these solutions will cause problems
with name conflicts, but that isn't hard to overcome if you have a naming
convention for archiving pre-existing files.
>
As I mentioned in another post, my problem is that due to the sheer volume
of the data 3/4 of a terabyte or so, I simply can't do anything that copies
then removes. I just don't have the room.
Good suggestions otherwise, though.


Paul Archer

#19346 From: merlyn@...
Date: Tue Aug 3, 2004 10:34 pm
Subject: Re: [PBML] moving files to existing structure
merlynstoneh...
Send Email Send Email
 
>>>>> "Paul" == Paul Archer <tigger@...> writes:

Paul> Now, it may be that there's a simple solution. It may be that
Paul> I'm being lazy ("beyond reproach", even) for asking for help
Paul> rather than slogging it out completely on my own (but I don't
Paul> think so). But I doubt a workable solution is going to fit in 8
Paul> lines of code.

Here's the exact code that would do the job.  The first two initialize
your parameters.  I don't count those, because those could have been
envars or @ARGV.  Three of the lines are "use", using two core modules
and one CPAN module.  The remaining 5 lines perform precisely the task
you want, but I've "X'ed" those out because you haven't sent me a
check yet.

     my $SRC = "/somedir/traces";
     my $DST = "/data/traces";
     XXX XXXXXXXXXXXXX
     XXX XXXXXXXXXXX
     XXX XXXXXXXXXXXXXXX
     XXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX X
       XXX XXXX X XXX XX XXXXXXXXXXXXXXXX
       XXXXXXXXXXXXXXXXXXXXXX
       XXXXXXXXXXXXXXXX
     X

Eight lines of code exactly.  Yeah, that was a guess when I first
though of it, but the code bears it out.

Now stop your whining.  Either learn some Perl, or hire someone
to turn those X's back into code.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

#19347 From: Jeff 'japhy' Pinyan <japhy@...>
Date: Tue Aug 3, 2004 10:36 pm
Subject: Re: [PBML] moving files to existing structure
evilffej
Send Email Send Email
 
On Aug 3, Paul Archer said:

>I've got a bunch (thousands) of files in a structure like this:
>
>/somedir/traces/2004/08/03/abc/longfilename.abi
>
>and I need to move them to another directory structure that already has some
>directories in place:
>
>/data/traces/2004/08/03/abc/longfilename.abi
>
>where /data/traces/2004/08/03 (for example) may or may not exist.

Couldn't you do:

   use File::Basename 'fileparse';
   use File::Path 'mkpath';

   for (@list_of_files) {
     my ($file, $path) = fileparse($_);
     (my $new_path = $path) =~ s{^/somedir}{/data};
     mkpath $new_path
       or warn "couldn't mkpath $new_path: $!";
     rename $_ => "$new_path/$file"
       or warn "couldn't mv $_ to $new_path/$file: $!";
   }

--
Jeff "japhy" Pinyan         %  How can we ever be the sold short or
RPI Acacia Brother #734     %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %    -- Meister Eckhart

#19348 From: "Jeff Eggen" <jeggen@...>
Date: Tue Aug 3, 2004 10:41 pm
Subject: Re: [PBML] moving files to existing structure
jeggen@...
Send Email Send Email
 
>>> tigger@... 03/08/2004 3:27:27 pm >>>
>As I mentioned in another post, my problem is that due to the sheer volume
>of the data 3/4 of a terabyte or so, I simply can't do anything that copies
>then removes. I just don't have the room.
>Good suggestions otherwise, though.

Then the move suggestion should work for you.  They didn't all involve copying.

cd /somedir/traces
for i in `find . -print | sort`
do
([ -d $i ] && [ -x /data/traces/$i ]) || mkdir /data/traces/$i
[ -f /data/traces/$i ] && mv /data/traces/$i /data/traces/${i}.archived
[ -f $i ] && mv $i /data/traces/$i
done

Kind of verbose at 7 lines, but it'll get the job done, and won't require any
more space.  Explicit for those who want explicitness, I guess.  The second line
that begins with "test" should take care of file name conflicts, but won't do
anything about directories.  I tried it here on one of my rigs, and it seems to
work.

And for the record: you never mentioned the space requirements being a
restriction.  You just mentioned that there were a lot of files, which doesn't
mean much.

Hope this helps,

Jeff Eggen
IT Programmer Analyst
Saskatchewan Government Insurance
Ph (306) 751-1795
email jeggen@...

************DISCLAIMER*************
This e-mail and any files transmitted with it are confidential and intended
solely for the use of the individual or entity to whom they are addressed.  If
you are not the named addressee, please notify the sender immediately by e-mail
if you have received this e-mail by mistake and delete this e-mail from your
system. If you are not the intended recipient you are notified that using,
disclosing, copying or distributing the contents of this information is strictly
prohibited.
************DISCLAIMER*************

#19349 From: "Irek Rybark" <irek@...>
Date: Wed Aug 4, 2004 3:11 am
Subject: Script is not working in CGI but is working locally
irekrybark
Send Email Send Email
 
Hi!
I am new to perl and CGI.  I am even not sure that this is
more perl or CGI problem.

I am trying to use CSV module by Christopher Rath
http://rath.ca/Misc/Perl_CSV/index.shtml
to parse some comma separated file.
My problem is that my script is **not working on a server**,
however is **working on my local box** (W2k command prompt).

This is an output on my box:
================================================
C:\Perl\lib\CSV-2\Demo_App>perl CSV_test.cgi
Content-type: text/html
Item Number,Item Name,Item Description,Item Type
<p>    J00E0001, Tirbal Necklace, Charming tribal necklace </p>
<p>    J00T0001, Jade Necklace, Beautiful Chinese jade necklace </p>
================================================

This is an output from HTTP server: (you can see it with your own
eyes: http://sutherlandstudios.netfirms.com/cgi/cgierr.pl/cgi-
bin/CSV_test.cgi)
================================================
Content-type: text/html Item Number,Item Name,Item Description,Item
Type Oups! Some fields are missing from the input file.end
================================================
What could be wrong?
I appreciate any feedback,
Irek



Perl version: 5.6.1 (local and the server)
Script to download: http://sutherlandstudios.netfirms.com/CSV_test.cgi

Actually, suspecting some problems with calling functions from
external module I put test code into CGI module.

Key part of the scrit follows:
================================================
#!/usr/bin/perl -w
use strict;
print "Content-type: text/html\n";
$CSV::Delimiters = undef;
my(%CSVDefaultColumnMapping) = ("" => -1);

my($ITEM_NUM) = "Item Number";
my($ITEM_NAME) = "Item Name";
my($ITEM_DESC) = "Item Description";
my($ITEM_TYPE) = "Item Type";

my($input)      = "items.csv"; #$ARGV[0];
my($item_type)  = "NECKLACE"; #$ARGV[1];

if (!open(INPUT, "$input")) {
     die "$0: ERROR, cannot open input file, $input\n"
       ."\tno data generated.\n";
} else {
     my($firstLine) = scalar(<INPUT>);
     my(%CSVfields) = CSVinit($firstLine);

     print$firstLine;

     if (! CSVvalidate(\%CSVfields, $ITEM_NUM, $ITEM_NAME, $ITEM_DESC,
$ITEM_TYPE)) {
# die "Some fields are missing from the input file.";
         print "Oups! Some fields are missing from the input file.";
     } else {
	 my(@record); # Where we'll store parsed records.
	 my($outrec); #Output record (a string).

	 while (<INPUT>) {
	     @record = CSVsplit($_);
	     if ("\U$record[$CSVfields{$ITEM_TYPE}]"
eq "\U$item_type") {
		 printf "<p>    %s, %s, %s </p>\n",
                     "$record[$CSVfields{$ITEM_NUM}]",
                     "$record[$CSVfields{$ITEM_NAME}]",
                     "$record[$CSVfields{$ITEM_DESC}]";
	     }
	 }
     }
}
##### THE REST HAS BEEN REMOVED

#19350 From: daymobrew@...
Date: Wed Aug 4, 2004 8:31 am
Subject: Re: Script is not working in CGI but is working locally
daymobrew
Send Email Send Email
 
--- In perl-beginner@yahoogroups.com, "Irek Rybark" <irek@p...> wrote:
> Hi!
> I am new to perl and CGI.  I am even not sure that this is
> more perl or CGI problem.
>
> I am trying to use CSV module by Christopher Rath
> http://rath.ca/Misc/Perl_CSV/index.shtml
> to parse some comma separated file.
> My problem is that my script is **not working on a server**,
> however is **working on my local box** (W2k command prompt).
>
> This is an output on my box:
> ================================================
> C:\Perl\lib\CSV-2\Demo_App>perl CSV_test.cgi
> Content-type: text/html
> Item Number,Item Name,Item Description,Item Type
> <p>    J00E0001, Tirbal Necklace, Charming tribal necklace </p>
> <p>    J00T0001, Jade Necklace, Beautiful Chinese jade necklace </p>
> ================================================
>
> This is an output from HTTP server: (you can see it with your own
> eyes: http://sutherlandstudios.netfirms.com/cgi/cgierr.pl/cgi-
> bin/CSV_test.cgi)
> ================================================
> Content-type: text/html Item Number,Item Name,Item Description,Item
> Type Oups! Some fields are missing from the input file.end
> ================================================
> What could be wrong?
> I appreciate any feedback,
> Irek
>
>
>
> Perl version: 5.6.1 (local and the server)
> Script to download: http://sutherlandstudios.netfirms.com/CSV_test.cgi
>
> Actually, suspecting some problems with calling functions from
> external module I put test code into CGI module.
>
> Key part of the scrit follows:
> ================================================
> #!/usr/bin/perl -w
> use strict;
> print "Content-type: text/html\n";
> $CSV::Delimiters = undef;
> my(%CSVDefaultColumnMapping) = ("" => -1);
>
> my($ITEM_NUM) = "Item Number";
> my($ITEM_NAME) = "Item Name";
> my($ITEM_DESC) = "Item Description";
> my($ITEM_TYPE) = "Item Type";
>
> my($input)      = "items.csv"; #$ARGV[0];
> my($item_type)  = "NECKLACE"; #$ARGV[1];
>
> if (!open(INPUT, "$input")) {
>     die "$0: ERROR, cannot open input file, $input\n"
>       ."\tno data generated.\n";
> } else {
>     my($firstLine) = scalar(<INPUT>);
>     my(%CSVfields) = CSVinit($firstLine);
>
>     print$firstLine;
>
>     if (! CSVvalidate(\%CSVfields, $ITEM_NUM, $ITEM_NAME, $ITEM_DESC,
> $ITEM_TYPE)) {
> # die "Some fields are missing from the input file.";
>         print "Oups! Some fields are missing from the input file.";
>     } else {
>  my(@record); # Where we'll store parsed records.
>  my($outrec); #Output record (a string).
>
>  while (<INPUT>) {
> 	    @record = CSVsplit($_);
> 	    if ("\U$record[$CSVfields{$ITEM_TYPE}]"
> eq "\U$item_type") {
> 	 printf "<p>    %s, %s, %s </p>\n",
>                     "$record[$CSVfields{$ITEM_NUM}]",
>                     "$record[$CSVfields{$ITEM_NAME}]",
>                     "$record[$CSVfields{$ITEM_DESC}]";
> 	    }
>  }
>     }
> }
> ##### THE REST HAS BEEN REMOVED

So, it seems that CSVvalidate() is failing.
One possibility - the input file was uploaded by ftp as binary instead
of ascii? It might make (though shouldn't) make a difference.

BTW, your Content-Type is html but you aren't providing '<html>'
and '<body>' tags. Also,
print "Content-type: text/html\n";
should have two '\n'.
I find the CGI module helpful for headers and other CGI functionality.
You may not need it if your script is not responding to a form.

Damien.

#19351 From: "Irek Rybark" <irek@...>
Date: Wed Aug 4, 2004 12:24 pm
Subject: Re: Script is not working in CGI but is working locally
irekrybark
Send Email Send Email
 
Hello!
Bull's-eye!
I re-uploaded the file in text mode and it is working.  Does it have
something to do with CR/LF conversion?
Thanks a lot for the hint!

Btw, why
> print "Content-type: text/html\n";
> should have two '\n'.
?

Irek

--- In perl-beginner@yahoogroups.com, daymobrew@y... wrote:
> --- In perl-beginner@yahoogroups.com, "Irek Rybark" <irek@p...>
wrote:
> > Hi!
> > I am new to perl and CGI.  I am even not sure that this is
> > more perl or CGI problem.
> >
>..... CUT!

> So, it seems that CSVvalidate() is failing.
> One possibility - the input file was uploaded by ftp as binary
instead
> of ascii? It might make (though shouldn't) make a difference.
>
> BTW, your Content-Type is html but you aren't
providing '<html>'
> and '<body>' tags. Also,
> print "Content-type: text/html\n";
> should have two '\n'.
> I find the CGI module helpful for headers and other CGI
functionality.
> You may not need it if your script is not responding to a form.
>
> Damien.

#19352 From: Paul Archer <tigger@...>
Date: Wed Aug 4, 2004 2:15 pm
Subject: Re: [PBML] moving files to existing structure
tigger@...
Send Email Send Email
 
Yesterday, Randal L. Schwartz wrote:

> >>>>> "Paul" == Paul Archer <tigger@...> writes:
>
> Paul> Now, it may be that there's a simple solution. It may be that
> Paul> I'm being lazy ("beyond reproach", even) for asking for help
> Paul> rather than slogging it out completely on my own (but I don't
> Paul> think so). But I doubt a workable solution is going to fit in 8
> Paul> lines of code.
>
> Here's the exact code that would do the job.  The first two initialize
> your parameters.  I don't count those, because those could have been
> envars or @ARGV.  Three of the lines are "use", using two core modules
> and one CPAN module.  The remaining 5 lines perform precisely the task
> you want, but I've "X'ed" those out because you haven't sent me a
> check yet.
>
>     my $SRC = "/somedir/traces";
>     my $DST = "/data/traces";
>     XXX XXXXXXXXXXXXX
>     XXX XXXXXXXXXXX
>     XXX XXXXXXXXXXXXXXX
>     XXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX X
>       XXX XXXX X XXX XX XXXXXXXXXXXXXXXX
>       XXXXXXXXXXXXXXXXXXXXXX
>       XXXXXXXXXXXXXXXX
>     X
>
> Eight lines of code exactly.  Yeah, that was a guess when I first
> though of it, but the code bears it out.
>
> Now stop your whining.  Either learn some Perl, or hire someone
> to turn those X's back into code.
>


I've seen you slap other people down before. I've even been guilty of
following suit. Glad it's happened to me now, so I know what it feels like,
and I can make sure I don't play the asshole again the next time I feel like
stomping on someone for what I feel is an unreasonable post.

FWIW, I did word my original post poorly, and left out some important
details--like the fact that I was looking for hints, not 8 lines of
carefully crafted code by the Master; or that I had to run this rename on
over 3.6 million files comprising almost a terabyte of data and 4 days of
tape restores, and I was really nervous about doing something wrong, as well
as worried about efficiency.

Perhaps had I mentioned those facts, you would have been less harsh. But
it's a bit late now for both of us.

Paul Archer

#19353 From: Paul Archer <tigger@...>
Date: Wed Aug 4, 2004 2:18 pm
Subject: Re: [PBML] moving files to existing structure
tigger@...
Send Email Send Email
 
I had no idea the mkpath subroutine was out there. I ended up doing a
system ("mkdir", "-p", "$dir")
but next time I'll definitely use mkpath instead.
Thanks for the tip!

Paul

Yesterday, Jeff 'japhy' Pinyan wrote:

> On Aug 3, Paul Archer said:
>
> >I've got a bunch (thousands) of files in a structure like this:
> >
> >/somedir/traces/2004/08/03/abc/longfilename.abi
> >
> >and I need to move them to another directory structure that already has some
> >directories in place:
> >
> >/data/traces/2004/08/03/abc/longfilename.abi
> >
> >where /data/traces/2004/08/03 (for example) may or may not exist.
>
> Couldn't you do:
>
>   use File::Basename 'fileparse';
>   use File::Path 'mkpath';
>
>   for (@list_of_files) {
>     my ($file, $path) = fileparse($_);
>     (my $new_path = $path) =~ s{^/somedir}{/data};
>     mkpath $new_path
>       or warn "couldn't mkpath $new_path: $!";
>     rename $_ => "$new_path/$file"
>       or warn "couldn't mv $_ to $new_path/$file: $!";
>   }
>
> --
> Jeff "japhy" Pinyan         %  How can we ever be the sold short or
> RPI Acacia Brother #734     %  the cheated, we who for every service
> http://japhy.perlmonk.org/  %  have long ago been overpaid?
> http://www.perlmonks.org/   %    -- Meister Eckhart
>
>
>
>
> Unsubscribing info is here:
http://help.yahoo.com/help/us/groups/groups-32.html
> Yahoo! Groups Links
>
>
>
>
>

--------------------------------------------------------------
"I'd cry/cry for the future/but I wouldn't get anything done."
----------------------Hunters + Collectors--------------------

#19354 From: Paul Archer <tigger@...>
Date: Wed Aug 4, 2004 2:21 pm
Subject: Re: [PBML] moving files to existing structure
tigger@...
Send Email Send Email
 
> >>> tigger@... 03/08/2004 3:27:27 pm >>>
> >As I mentioned in another post, my problem is that due to the sheer volume
> >of the data 3/4 of a terabyte or so, I simply can't do anything that copies
> >then removes. I just don't have the room.
> >Good suggestions otherwise, though.
>
> Then the move suggestion should work for you.  They didn't all involve
copying.
>
> cd /somedir/traces
> for i in `find . -print | sort`
> do
> ([ -d $i ] && [ -x /data/traces/$i ]) || mkdir /data/traces/$i
> [ -f /data/traces/$i ] && mv /data/traces/$i /data/traces/${i}.archived
> [ -f $i ] && mv $i /data/traces/$i
> done
>
> Kind of verbose at 7 lines, but it'll get the job done, and won't require
> any more space.  Explicit for those who want explicitness, I guess.  The
> second line that begins with "test" should take care of file name
> conflicts, but won't do anything about directories.  I tried it here on
> one of my rigs, and it seems to work.
>
Thanks for the code. I ended up doing it in Perl, but it's always nice to
see how different people handle the same task.



> And for the record: you never mentioned the space requirements being a
> restriction.  You just mentioned that there were a lot of files, which
> doesn't mean much.
>

You are quite right. I should have mentioned it. The whole reason for my
original post, after all, was that I had millions of files to move, and was
afraid that it would take forever (and I was pretty nervous about messing
something up, as that could mean having to pull this data off of tape
*again*, a process that took 4 days the first time).

Paul Archer

#19355 From: merlyn@...
Date: Wed Aug 4, 2004 2:32 pm
Subject: Re: [PBML] moving files to existing structure
merlynstoneh...
Send Email Send Email
 
>>>>> "Paul" == Paul Archer <tigger@...> writes:

Paul> FWIW, I did word my original post poorly, and left out some important
Paul> details--like the fact that I was looking for hints,

And I gave you those hints.  My first response was a series
of perldoc commands that would have led you to most of the solution
I posted.

Paul>  not 8 lines of
Paul> carefully crafted code by the Master;

And while your solution might not have been 8 lines, that was part of
my first response to show you that the task is NOT HARD.

Paul>  or that I had to run this rename on
Paul> over 3.6 million files comprising almost a terabyte of data and 4 days of
Paul> tape restores, and I was really nervous about doing something wrong, as
well
Paul> as worried about efficiency.

And if you weren't confident to do that yourself, you should have
HIRED SOMEONE.  Not asked for FREE LABOR on a technical discussion
list.

Paul> Perhaps had I mentioned those facts, you would have been less harsh. But
Paul> it's a bit late now for both of us.

I'm only harsh when I see people misunderstanding the purpose of a
technical mailing list, or wanting to be SO LAZY to get others to do
their work for them.

I have absolutely no problem with people showing effort, then getting
stuck, then asking for the next step here.  I help people like that
here (and all over) all the time.  Maybe you should try to understand
why you didn't come across like that, but rather like someone who
wanted the world for free, instead of working toward your goal.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

#19356 From: daymobrew@...
Date: Thu Aug 5, 2004 10:10 am
Subject: Re: Script is not working in CGI but is working locally
daymobrew
Send Email Send Email
 
--- In perl-beginner@yahoogroups.com, "Irek Rybark" <irek@p...> wrote:
> Hello!
> Bull's-eye!
> I re-uploaded the file in text mode and it is working.  Does it have
> something to do with CR/LF conversion?
Yes

> Btw, why
> > print "Content-type: text/html\n";
> > should have two '\n'.
> ?
Headers (and 'Content-type' is one) always need a blank line before
the data.

>
> Irek
>
> --- In perl-beginner@yahoogroups.com, daymobrew@y... wrote:
> > --- In perl-beginner@yahoogroups.com, "Irek Rybark" <irek@p...>
> wrote:
> > > Hi!
> > > I am new to perl and CGI.  I am even not sure that this is
> > > more perl or CGI problem.
> > >
> >..... CUT!
>
> > So, it seems that CSVvalidate() is failing.
> > One possibility - the input file was uploaded by ftp as binary
> instead
> > of ascii? It might make (though shouldn't) make a difference.
> >
> > BTW, your Content-Type is html but you aren't
> providing '<html>'
> > and '<body>' tags. Also,
> > print "Content-type: text/html\n";
> > should have two '\n'.
> > I find the CGI module helpful for headers and other CGI
> functionality.
> > You may not need it if your script is not responding to a form.
> >
> > Damien.

#19357 From: Luca Ferrari <fluca1978@...>
Date: Thu Aug 5, 2004 11:41 am
Subject: regular expression help
fluca1978@...
Send Email Send Email
 
Hi,
supposing I've got a string like the following:
a.b.c.d.e.f
and that I'd like to keep only the first characters before the first
'.' (e.g., 'a'), why the following is not working?

$string =~ s/^(.+)\.(.*)/$1/;

Applied to the above example string it gives me back only 'f'. Any
explanation?

Thanks,
Luca


--
Luca Ferrari,
fluca1978@...

#19358 From: Gordon Stewart <gordonisnz@...>
Date: Thu Aug 5, 2004 12:27 pm
Subject: Re: [PBML] regular expression help
gordonisnz@...
Send Email Send Email
 
On Thu, 5 Aug 2004 13:41:35 +0200, Luca Ferrari <fluca1978@...> wrote:

> $string =~ s/^(.+)\.(.*)/$1/;
>
> Applied to the above example string it gives me back only 'f'. Any
> explanation?
>
> Thanks, Luca

untested - but try :-

$string =~ s/^(.+?)\.(.*)/$1/;

you get 'f' because F still precedes a . (dot)...

put the ? in, to restrict it to the first match (or non-match)

--

G Stewart
gmail-talk-help@yahoogroups.com

#19359 From: "Madani, Srikanth, VF-DE" <srikanth.madani@...>
Date: Thu Aug 5, 2004 12:29 pm
Subject: RE: [PBML] regular expression help
ihaveitinme
Send Email Send Email
 
Hi Luca,

I'm not sure if I get the requirement. If you wish to _retain_ the one character
before the initial period, this is how I would do it:

chomp (my $string = <>);
if ($string =~ /^(.)\./) {
         $string = $1;
         print "\nThe string has been changed to $string\n";
} else {
         print "\nThe string $string doesn't match the expected criterion.\n";
}


Best regards,
Srikanth Madani


-----Original Message-----
From: Luca Ferrari [mailto:fluca1978@...]
Sent: Thursday, August 05, 2004 12:42 PM
To: perl-beginner@yahoogroups.com
Subject: [PBML] regular expression help


Hi,
supposing I've got a string like the following:
a.b.c.d.e.f
and that I'd like to keep only the first characters before the first
'.' (e.g., 'a'), why the following is not working?

$string =~ s/^(.+)\.(.*)/$1/;

Applied to the above example string it gives me back only 'f'. Any
explanation?

Thanks,
Luca


--
Luca Ferrari,
fluca1978@...

#19360 From: "JORGE SILVA" <jorge.reissilva@...>
Date: Thu Aug 5, 2004 12:43 pm
Subject: RE: [PBML] regular expression help
jorge.reissilva@...
Send Email Send Email
 
I think this code should work...

#------------------------------------
my ($a, $b);
$a = "a.b.c.d.e.f.";
($b) = split(/\./,$a);
print $b, "\n";
#------------------------------------

Best Regards,

Jorge Silva.

| -----Original Message-----
| From: Madani, Srikanth, VF-DE [mailto:srikanth.madani@...]
| Sent: quinta-feira, 5 de Agosto de 2004 13:29
| To: perl-beginner@yahoogroups.com
| Subject: RE: [PBML] regular expression help
|
|
| Hi Luca,
|
| I'm not sure if I get the requirement. If you wish to
| _retain_ the one character before the initial period, this is
| how I would do it:
|
| chomp (my $string = <>);
| if ($string =~ /^(.)\./) {
|         $string = $1;
|         print "\nThe string has been changed to $string\n";
| } else {
|         print "\nThe string $string doesn't match the
| expected criterion.\n";
| }
|
|
| Best regards,
| Srikanth Madani
|
|
| -----Original Message-----
| From: Luca Ferrari [mailto:fluca1978@...]
| Sent: Thursday, August 05, 2004 12:42 PM
| To: perl-beginner@yahoogroups.com
| Subject: [PBML] regular expression help
|
|
| Hi,
| supposing I've got a string like the following:
| a.b.c.d.e.f
| and that I'd like to keep only the first characters before the first
| '.' (e.g., 'a'), why the following is not working?
|
| $string =~ s/^(.+)\.(.*)/$1/;
|
| Applied to the above example string it gives me back only 'f'. Any
| explanation?
|
| Thanks,
| Luca
|
|
| --
| Luca Ferrari,
| fluca1978@...
|
|
| ------------------------ Yahoo! Groups Sponsor
| --------------------~-->
| Yahoo! Domains - Claim yours for only $14.70
| http://us.click.yahoo.com/Z1wmxD/DREIAA/yQLSAA/ndFolB/TM
| --------------------------------------------------------------
| ------~->
|
| Unsubscribing info is here:
| http://help.yahoo.com/help/us/groups/groups-32.html
| Yahoo! Groups Links
|
|
|
|
|
|


This message may contain confidential and/or privileged information and is
intended solely for the use of the individual or entity to whom is addressed. If
you are not the intended recipient, then any disclosure, copying, distribution
or any other action in reliance upon is expressly prohibited and may be
unlawful. In this case, please advise the sender by replying and deleting this
message.
Any opinions or advices contained in this message or attachments are the sole
responsibility of the sender and do not necessarily represent Banco Comercial
Portugues.
This e-mail message has been swept by Mimesweeper for the presence of computer
viruses.

#19361 From: "Luinrandir Hernsen" <Luinrandir@...>
Date: Thu Aug 5, 2004 1:49 pm
Subject: question about @ and Files
Luinrandir
Send Email Send Email
 
the info to the file is written like this
axe,sox,dog,fox,
can I read this from the file as an array?
@A=<FileName>;
I am also looking for info on homemade databases.

I can't use SQL or other ready made database.


Lou


[Non-text portions of this message have been removed]

#19362 From: Brad Lhotsky <brad@...>
Date: Thu Aug 5, 2004 2:04 pm
Subject: Re: [PBML] regular expression help
brad@...
Send Email Send Email
 
Perl's + and * Quantifiers are greedy.

In other words, they grab everything from the beginning of the line on
through the end.  I wrote a Regex primer a while back:

http://www.developer.com/lang/perl/article.php/3330231

I know I covered greedy vs. non-greedy in there.

and I'm sure Randal has atleast one column on this exact thing somewhere
on his site at:
http://www.stonehenge.com/merlyn/columns.html

In this case, I'm thinking that you know exactly what you're not looking
for, so it might be easier to look for that:

#!/usr/bin/perl

use strict;

my @strings = qw(
     a.b.c.d.f.e.a
     sdg.sd.s..sdg.s.d
     321.asf..124124
     sfkjlgasfkakjsfasfasmf.asfaaga..
     .fasfasgasgasg
     45.asfagaxcb.
);

foreach my $string (@strings) {
     my ($match) = ($string =~ /^([^\.]{0,2})/);
     print "$string :: '$match'\n";
}


Enjoy.

On Thu, Aug 05, 2004 at 01:41:35PM +0200, Luca Ferrari wrote:
> Hi,
> supposing I've got a string like the following:
> a.b.c.d.e.f
> and that I'd like to keep only the first characters before the first
> '.' (e.g., 'a'), why the following is not working?
>
> $string =~ s/^(.+)\.(.*)/$1/;
>
> Applied to the above example string it gives me back only 'f'. Any
> explanation?
>
> Thanks,
> Luca
>
>
> --
> Luca Ferrari,
> fluca1978@...
>
>
>
> Unsubscribing info is here:
http://help.yahoo.com/help/us/groups/groups-32.html
> Yahoo! Groups Links
>
>
>
>
>

--
Brad Lhotsky <brad@...>

#19363 From: Brad Lhotsky <brad@...>
Date: Thu Aug 5, 2004 2:07 pm
Subject: Re: [PBML] regular expression help
brad@...
Send Email Send Email
 
For some reason, my initial reading of this post was the first two
characters before the first '.'.  Weird.

Anyways, ignore my other code, do this:

my $match = (split '.', $string)[0];

On Thu, Aug 05, 2004 at 01:41:35PM +0200, Luca Ferrari wrote:
> Hi,
> supposing I've got a string like the following:
> a.b.c.d.e.f
> and that I'd like to keep only the first characters before the first
> '.' (e.g., 'a'), why the following is not working?
>
> $string =~ s/^(.+)\.(.*)/$1/;
>
> Applied to the above example string it gives me back only 'f'. Any
> explanation?
>
> Thanks,
> Luca
>
>
> --
> Luca Ferrari,
> fluca1978@...
>
>
>
> Unsubscribing info is here:
http://help.yahoo.com/help/us/groups/groups-32.html
> Yahoo! Groups Links
>
>
>
>
>

--
Brad Lhotsky <brad@...>

#19364 From: Luca Ferrari <fluca1978@...>
Date: Thu Aug 5, 2004 2:13 pm
Subject: Re: [PBML] question about @ and Files
fluca1978@...
Send Email Send Email
 
On Thursday 05 August 2004 15:49 Luinrandir Hernsen's cat walking on the
keyboard  wrote:

> the info to the file is written like this
> axe,sox,dog,fox,
> can I read this from the file as an array?
> @A=<FileName>;
> I am also looking for info on homemade databases.
>
> I can't use SQL or other ready made database.
>

You can surely convert into an array:
$line = <FILENAME>;
@A = split(",",$line);

Luca

--
Luca Ferrari,
fluca1978@...

#19365 From: Luca Ferrari <fluca1978@...>
Date: Thu Aug 5, 2004 2:15 pm
Subject: Re: [PBML] regular expression help
fluca1978@...
Send Email Send Email
 
On Thursday 05 August 2004 13:41 Luca Ferrari's cat walking on the keyboard
wrote:

> Hi,
> supposing I've got a string like the following:
> a.b.c.d.e.f
> and that I'd like to keep only the first characters before the first
> '.' (e.g., 'a'), why the following is not working?
>
> $string =~ s/^(.+)\.(.*)/$1/;
>
> Applied to the above example string it gives me back only 'f'. Any
> explanation?
>

Hi guys,
thanks everybody for the help.
The solution I adopted is
$string =~ s/^(.+?)\.(.*)/$1/;

I know that I could use split, but since perl has a regexp engine why don't
use it?

Thanks everybody,
Luca

--
Luca Ferrari,
fluca1978@...

Messages 19336 - 19365 of 27459   Oldest  |  < Older  |  Newer >  |  Newest
Add to My Yahoo!      XML What's This?

Copyright © 2010 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines NEW - Help