"West, William M" <[EMAIL PROTECTED]> writes:

> i'd like to take a couple of strings to concatonate to a path...
> 
> here's my start the code:::
> 
> #!/usr/bin/perl -w
> 
> 
> use strict;
> use diagnostics;
> 
> my $date = `date`; #not sure about redirecting output to $path!
> 
> $date=~s/( ){3}/; #i think this is proper to just take the string
>                       #up to the third whitespace character...

Nope - I think:


$date =~ s/^(\S*\s\S*\s\S*).*/$1/s;


Will do it, though...I'm sure there are better ways, that's
just the first thing I though of - someone with more regexp-foo can
probably help there.

> my $filename = append_date_to_rest_of_filename();

Regarding the actualy concatenation, do you mean:

for the directory '/tmp/foo', get back '/tmp/foo-Mon Jun 16'?

If so, just use the '.' operator:

my $dir = '/tmp/foo-' . $date;

If you want to get '/tmp/foo/Mon Jun 16', use File::Spec->catfile.
Here's an example from a script I wrote to download images from a
digital camera, storing each new set of images in it's own directory
under todays date:



use POSIX;
use File::Spec

my $destination_path = '/tmp/foo;

my $date = strftime("%Y-%m-%d", localtime time);
my $target_dir = File::Spec->catfile($destination_path, $date);



So $target_dir is now '/tmp/foo/2003-06-16', for instance.

You'll notice I used strftime to get the date instead of parsing
`date` - probably easier and more correct.

For my script, I also check to make sure the directory in $target_dir
doesn't already exist - this may or may not apply for your
application, though.

-RN

-- 
Robin Norwood
Red Hat, Inc.

"The Sage does nothing, yet nothing remains undone."
-Lao Tzu, Te Tao Ching

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to