Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

sql entry of file name n size

by rajeshatbuzz (Novice)
on Jul 28, 2011 at 10:56 UTC ( #917244=perlquestion: print w/replies, xml ) Need Help??
rajeshatbuzz has asked for the wisdom of the Perl Monks concerning the following question:

following program can list the directory all files along with their size. Now i was trying this info to sql table in manner such as file name | size... while doing this facing many issues. any idea how to do?
$DIR = "/home/rajesh"; @dirlist = `ls -l $DIR | tr -s " " " "| cut -d " " -f5,9`; foreach (@dirlist) { print "$_ \n"; }

Replies are listed 'Best First'.
Re: sql entry of file name n size
by Corion (Pope) on Jul 28, 2011 at 11:00 UTC

    First, take a look at opendir and readdir to eliminate that ls | tr | cut pipe. Then, please take the time to tell us what you tried and what problems you encountered. That helps us to help you better.

    Maybe you want to interface to a database and store the information? Then DBI is what you need.

Re: sql entry of file name n size
by linuxer (Curate) on Jul 29, 2011 at 20:08 UTC

    Just a quick thought in addition to Corion's answer: Once you have read the directory and its entries, you maybe want to have a look at the File::Spec module to create the file paths and the -s operator to determine the file sizes.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://917244]
Approved by Corion
help
Chatterbox?
[Discipulus]: [OT] if i have an svg image (a map of italian provinces) like this one in which way i need to interact with it to have a geochart?
[Corion]: I haven't found a good way to plot stuff into country maps... Maybe one of the demos of D3.js has something usable?
[Discipulus]: i need to use css to get and colorize various different IDs?
[Corion]: I haven't used it, but http://datamaps. github.io/ looks promising
[Discipulus]: thanks.. a more perlish solution?

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (14)
As of 2017-03-23 09:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (285 votes). Check out past polls.