Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

sugession for the filecreating

by sanku (Beadle)
on Mar 24, 2008 at 06:08 UTC ( [id://675858]=perlquestion: print w/replies, xml ) Need Help??

sanku has asked for the wisdom of the Perl Monks concerning the following question:

hi monks, I would like to add alphabetic at the end of each and every file which is creating automatically. can any one give me sugession for it. Once the alphabetic over then again the file must be created as filenameA.txt .. filenameZ.txt filenameAA.txt.. Thanks in advance,

Replies are listed 'Best First'.
Re: sugession for the filecreating
by McDarren (Abbot) on Mar 24, 2008 at 06:23 UTC
    This should give you a clue:
    perl -le '$x=A;for(1..100){print $x++}'
      hi, i don't want it in for loop because i am going to run the program for each and every one hour. so, while compling the program second time i need to add the alphabetics at the end of the orginal file name
        I said it was a clue, not the whole solution :p

        And you obviously missed the clue. Let me explain....

        You want a sequence that goes A,B,....X,Y,Z,AA,AB, etc.... right?

        Then all you need to do is use the auto-increment operator (++). Suggest you have a read of perlop (look for the "Auto-increment and Auto-decrement" section).

        Cheers,
        Darren :)

Re: sugession for the filecreating
by ikegami (Patriarch) on Mar 24, 2008 at 06:12 UTC
    Which part are you having a problem with? (Listing a dir? Finding the current highest numbered file? Generating the next number? Creating a file?) What have you done so far?
      #!/usr/bin/perl use DBI; my $now = localtime(); push (@now,split(/\s/,$now)); $mm=$now[1]; $dd=$now[2]; $hh=$now[3]; $yy=$now[4]; $now1="$yy$mm$dd$hh"; #after this i need alphabetics like "$yy$mm$dd$hhA" "$yy$mm$dd$hhB" ... "$yy$mm$dd$hhZ" "$yy$mm$dd$hhAA" this is mysql code $dbh=DBI->connect('DBI:mysql:suntelivr','xxxx','xxxx') or $DBI::errstr +; $sth=$dbh->prepare("insert into sequenceno (filename) values ('$now1") +; $sth->execute; $sth=$dbh->prepare("select * from sequenceno"); $sth->execute; while(@ss=$sth->fetchrow_array()){ $now1=$ss[$i+1]."_".$ss[$i]; }

      Mar 24, 2008 at 18:34 UTC McDarren Added code tags, removed sensitive information from code.

Re: sugession for the filecreating
by ady (Deacon) on Mar 24, 2008 at 09:34 UTC
    Hi,

    If your problem is generating the alfabetic permutation for the filenames, that's not quite trivial. You can find a good discussion in the book Higher-Order Perl by Mark Jason Dominus.

    Here's some (slightly adapted) code snippets from the book, that you may find useful :


    Best regards,
    Allan Dystrup
Re: sugession for the filecreating
by roboticus (Chancellor) on Mar 24, 2008 at 21:14 UTC
    sanku:

    I see you've already got your answers. But I just have to ask: Why not just add the hour (and possibly minute) to your filename? That way, they'd automagically have different names as you mention that you're running it on an hourly basis.

    ...roboticus
Re: sugession for the filecreating
by DBAugie (Beadle) on Mar 24, 2008 at 11:58 UTC
    You're trying to create a sequence, right? Please see http://forums.mysql.com/read.php?61,143867,145839#msg-145839

    Update:

    Often the database system you are working with already has a way of doing what you think you have to do in Perl. TAMTOWTDI ... but using the technique native to the database can work a lot faster and easier than home-brewing your own code.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://675858]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2024-04-23 19:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found