My code is kind of not efficient.
Here is the code.
where index is 1.jpg or 1.gif. The program only knows "1"
if ($image_found == 1) {
if ( -e "$index.jpg" ) {
$old = 1;
system("/bin/mv -f $working_dir/$index.jpg
$working_dir/$index_$index.jpg");
$new_file = "$index_$index". ".jpg";
$new_file1 = "$index". ".jpg";
}
if ( -e "$index.gif" ) {
$old = 1;
system("/bin/mv -f $working_dir/$index.gif
$working_dir/$index_$index.gif");
$new_file = "$index_$index". ".gif";
$new_file1 = "$index". ".jpg";
}
## which var will content 3.jpg or 3.gif. The program only knows "3"
if ( -e "$which.jpg" ) {
$new = 1;
system("/bin/mv -f $working_dir/$which.jpg
$working_dir/$which_which.jpg");
$old_file = "$which_which". ".jpg";
$old_file1 = "$which".".gif";
}
if ( -e "$which.gif" ) {
$new = 1;
system("/bin/mv -f $working_dir/$which.gif
$working_dir/$which_$which.gif");
$old_file = "$which_$which".".gif";
$old_file1 = "$which".".gif";
}
if ( $old == 1 ) {
system("/bin/mv -f $working_dir/$new_file1 $working_dir/$old_file1");
}
if ( $new == 1 ) {
system("/bin/mv -f $working_dir/$new_file
$working_dir/$new_file1");
}
}
-----Original Message-----
From: u235sentinel [mailto:[EMAIL PROTECTED]
Sent: Tuesday, April 13, 2004 12:02 PM
Cc: [EMAIL PROTECTED]
Subject: Re: New to perl ...
What have you tried? Please post the code so we can help
Bajaria, Praful wrote:
>Hello,
>
>I would like to swap the file name only and not the extension or the
>content.
>
>Example:
>There are two file : 1.jpg and 3.jpg
>output = 1.jpg becomes 3.jpg and 3.jpg becomes 1.jpg
>
>OR
>
>1.jpg and 3.gif
>output = 1.jpg becomes 3.jpg and 3.gif becomes 1.gif
>here we are changing the name only and not the extension.
>
>Inside my program I don't know either files extension, but they will be
only
>"jpg or gif"
>
>Any help...
>
>
>
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>