"File" to "File$date"


Thanks for all your answers!

From all, I combinded the perfext solution:

rename("test.txt", "test" . &heute() . ".txt");

sub heute {
return (localtime(time))[3] . (localtime(time))[4] . =

Thanks ;)

-----Urspr=FCngliche Nachricht-----
Von: Sudarshan Raghavan [mailto:sraghav@india.hp.com]=20
Gesendet: Samstag, 14. September 2002 15:21
An: Perl beginners
Betreff: Re: AW: Rename "File" to "File$date"

On Sat, 14 Sep 2002, Sudarshan Raghavan wrote:

> #!/usr/local/bin/perl -w
> use strict;
> # The -w flag on the shebang line is one way to enable warnings, you
> # can also do it by a use warnings; at the start of your code.=20
> # Also note the use strict; The reason I am emphasising on this is
> # that this will point out some basic errors that will help you in=20
> # your learning.
> my ($day, $mon, $year) =3D (localtime)[3,4,5];
> # Type perldoc -f localtime on your prompt and read through the doc
> $mon++;
> $year +=3D 1900;
> while (<*.txt>) {
>     # This will loop through all *.txt files in your cwd.
>     # perldoc -f glob and perldoc File::Glob
>     (my $new_name =3D $_) =3D~ =

My bad, the same sprintf for every file. You can move the sprint above =
loop like this.

my $date_str =3D sprintf("%d%02d%d",$day,$mon,$year);
while (<*.txt>) {
   (my $new_name =3D $_) =3D~ s/\.txt$/${date_str}.txt/;
   rename ($_, $new_name);

>     # This regex replaces the '.txt' part of your filename into =
>     # form. perldoc perlretut, perldoc perlre, perldoc -f sprintf=20
>    =20
>     rename ($_, $new_name);
>     # perldoc -f rename
> }

To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org

9/13/2002 10:01:10 AM
perl.beginners 29380 articles. 4 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 3

Andreas Kauffmann wrote:

> Okay...
> Thanks for all your answers!
> From all, I combinded the perfext solution:
> rename("test.txt", "test" . &heute() . ".txt");
> sub heute {
> return (localtime(time))[3] . (localtime(time))[4] . ((localtime(time))[5]
> 1900);
> }

three seperate localtime() calls could be bad. consider if you run your 
script at the end of the month midnight just before the clock flipping to 
the first day of the next month, your first localtime function will give 
you that day, but your next localtime function will give you next month. 
you should combine the localtime functions into a single call

9/13/2002 6:47:47 PM
On Fri, 13 Sep 2002, Kauffmann, Andreas wrote:

> Okay...
> Thanks for all your answers!
> >From all, I combinded the perfext solution:
> rename("test.txt", "test" . &heute() . ".txt");
> sub heute {
> return (localtime(time))[3] . (localtime(time))[4] . ((localtime(time))[5]
> 1900);
> }

1) Why do you want to make 3 different calls to localtime, just the one 
would do.

2) You don't have to call localtime(time), just a localtime() would do.
Be default localtime uses the current time i.e. this is evaluated
as localtime(time)

3) Do you want to do this for only one file or for multiple files in the 

9/14/2002 1:59:17 PM

Similar Artilces:

Rename "File" to "File$date"
Hy everybody in the List! I have a Problem writing a little perl application... Im a very newbie to programming and need your help :) The Problem is: I have a file "dev.txt" and I want to rename it once a day (with a = cronjob) like "dev13092002.txt" So i need to rename it with a date variable. All I have at the moment is: #!/usr/bin/perl $d =3D `date`; $d =3D /pattern1(pattern2)/; sytem("cp test.txt test`$d`.txt"); Does anyone of you know how to do that? THANKS in advance! =09 | Telematikzentrum D=FCrrwangen GmbH &am...

Convert "xls" file to "txt" file
Hi, I hope someone can help. I need to convert an Excel spreadsheet to an ASCI text file, in order to import data into a datawindow. I want to try and avoid asking users to save their files as text files and there are issues surrounding the use of ODBC to link to Excel. I am currently able to view my Excel data by way of an OLE object but if I try "Getdata", only the first 72 rows are imported to a string or blob and then subsequently to the datawindow. So I am looking for an OLE function which will "save as" my file. Help would be greatly appeciated. ...

.ALLCOL("%COLUMN%", " ", ", ", ", ")
Do you know anyway for me to exclude a subset of columns returned by this function. We have two columns (rec_user and rec_datetime) which are in all of our tables, but when generating triggers I want automatically generate a script which does not include those two columns but does include all other columns in that table. Bruce I should add that I am using PD Bruce "Bruce Lamb" <lamb.bruce@mayo.edu> wrote in message news:6HgI315nCHA.155@forums.sybase.com... > Do you know anyway for me to exclude a subset of columns returned by this > function. ...

Precedence of "where" ("of", "is", "will")?
Nobody on #perl6 today could answer this one. Is: Str | Int where { $_ } the same as: (Str | Int) where { $_ } or: Str | (Int where { $_ }) ? Followup questions, Mr. President: What kind of operators are "where", "of", "is", and "will"? Is there a reason that S03 doesn't list them? What are their precedence(s)? -- Chip Salzenberg - a.k.a. - <chip@pobox.com> Open Source is not an excuse to write fun code then leave the actual work to others. Chip Salzenberg writes: &...

Visual Studio 2005. "Quick Find", "Quick Replace", "Find in Files", "Replace in Files" functionality no longer works
Hello, I just run into problem that find functionality is no longer working in Visual Studio 2005. "Quick Find", "Quick Replace", "Find in Files", "Replace in Files" functionality no longer responds. These are necessary functions when build any website. Any solutions on how to fix this problem?Improving lifestyles for luxury pets: TheFabulousPet In Menu bar click Window -> Reset Window Layout. It solves the problem.Improving lifestyles for luxury pets: TheFabulousPet...

Shortcut Key for "File" -> "Save As File"
Hi all, We can save as DataWindow Object into .XML file through "File-> Save As File" option (after opening DataWindow Object in PB). Here I am unable to identify shortcut key for "Save As File", can any one tell me the shortcut key is available or not? if yes, could you please tell me the shortcut key for "Save As File" menu item. Advanced thanks for your help. -Siva On Feb 4, 7:45=A0pm, Siva Prasad <sivamc...@gmail.com> wrote: > Hi all, > > We can save as DataWindow Object into .XML file through "File-> Save > As...

quotes, quotes, quotes...
I am getting this error and I know what is causing it, but I have no idea how to fix it, any help would be great. The script steps through the /var/log/messages file on a linux server and puts The entries into a mysql database. However when it gets to the 'hlt' line in the messages file it just barfs. The single quotes are freaking it out. I know about quotes but not how to use in this situation. Thanks, Paul Error: May 27 17:53:00 localhost kernel: Checking 'hlt' instruction... OK. <----- doesn't like this in the messages file DBD::mysql::st exec...

How do I get the "created on" and "modified on" dates from an uploaded file?
I have a web application that allows users to upload and download various kinds of files.  This is accomplished using the usual methods:   The FileUpload control for uploading...   Response.BinaryWrite for the downloads...On upload, I would like to be able read the file's "created on" and "modified on" dates, and then store them in a database along with the file. Likewise, when a user downloads a file - I would like to output the file with it's associated "created" and "modified" dates.I cannot find any information on how to do this. When you execute a "PostedFile.Sa...

File write error on file "acct" in module "GWEACCT".
--____HHJZYVOOFXDLYDIWHUSF____ Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: base64 Content-Disposition: inline; modification-date="Tue, 24 Sep 2007 10:15:42 -0400" VGhlIG1vcm5pbmcgb2YgV2VkLiBTZXB0IDE5dGguIHdlIHN3aXRjaGVkIG91ciBHV0lBIG92ZXIg dG8gdmVyc2lvbiBHVzYuNSBTUDYgZnJvbSB2ZXJzaW9uIEdXNS41LiAgVGhlIG5leHQgbW9ybmlu ZyB3ZSBzdGFydGVkIGdldHRpbmcgdGhlIGZvbGxvd2luZyBlcnJvciBpbiBvdXIgR1dJQSBsb2cg ZmlsZTsNCg0KMDktMjAtMDcgMDg6MjI6MTAgMCBVbmtub3duLCBlcnJvciBjb2RlID0gODIxMA0K MDktMjAtMDcgMDg6MjI6MjEgMCBNU0cgNDAwIERlZmVycmVkIGRlbGl2ZXJ5IGZpbGUgbWVtb3J5 IGVy...

File write error on file "acct" in module "GWEACCT"
Getting this on GWIA 6.02 scrolling across the screen. Runs on a Win2ksp3 box. Searching TID's...... JG I'd probably whack most of the subdirs under gwia and let gwia rebuild. -- Michael J. Bell Novell Support Connection Volunteer Sysop Author of Guinevere (http://www.openhandhome.com) PLEASE: Do not e-mail me privately unless specifically asked. I'm a volunteer, not a Novell employee! All opinions and advice provided are MINE alone and NOT Novell's unless specifically identified as such. Novell does not officially monitor these forums. Enhance...

Hello I moved my application from IIS6 to IIS7 on windows server 2008.   And now, when a user try to download, from my web application , a file with a filename that contains the "+" sign, I get the "404 - File or directory not found." error message.For example "20-requirement+result.doc" would generate an error.It uses to work fine on windows server 2003 with IIS6.thanks in advance for your help Look in the IIS config file Its located in the System32 Directory - ex.   C:\Windows\system32\inetsrv\config\applicationHost.config L...

Is there a way to write Atlas "text/xml-script" script Into single file like ".js" or ".css" file
I have tried the following code: <script type="text/xml-script" src="Default.aspx.ajax"><script type="text/xml-script" src="Default.aspx.js"><script type="text/xml-script" src="Default.xml"> but they dit dot work. thanks.msn & email:lidong6@gmail.com I believe it does not work as the XML-Script processor takes the content within the script tags to do processing and ignores the src tag. I think this will be a nice feature to add in the next release....

"Link-", "Libs-" and "Import-" -entries in CB2010-project file
Hi. Could anyone explain to me, what the meaning of the different "link/lib/import"-entries in the project-file is? I'm confused. Using the GUI there is only the "Runtime package"-list - the reason and function for that one, I do understand. But what do the others? And which one *is* the "Runtime package"-list?? <LinkPackageStatics></LinkPackageStatics> <LinkPackageImports></LinkPackageImports> <PackageImports></PackageImports> <AllPackageLibs></AllPackageLibs> Thanks a lot! Best Regards Eike Pete...

while saving the file "Save as Type" in SaveDialogBox shows "MicrosoftExcelSheet" and "AllFiles", how can i restrict "AllFiles" and show only "MicrosoftExcelSheet" ..
Below is code written for opening XLFile.  HttpContext.Current.Response.Clear();HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + astr_FileName); HttpContext.Current.Response.AddHeader("Content-Length", abyte_Data.Length.ToString()); HttpContext.Current.Response.ContentType = astr_ContentType; //octet-stream"; or //"application/vnd.ms-excel"; HttpContext.Current.Response.BinaryWrite(abyte_Data);    Udaya.M...

Web resources about - "File" to "File$date" - perl.beginners

Resources last updated: 1/23/2016 1:48:10 PM