I used MP3::Tag to get ID3 information from mp3 file.
But I don't know how to get length of mp3 file..
I mean duration.
# get some information about the file in the easiest way
($title, $track, $artist, $album, $comment, $year, $genre) = $mp3->autoinfo();
This one don't have function which is getting length from ID3.
Anyone knows how I can get length of mp3 file in Perl?
If you are still looking for the answer, install MP3::Info and use:
$mp3->time_mm_ss();
Other things you can use:
total_secs()
total_secs_int()
total_mins()
leftover_secs()
leftover_msec()
See the bottom of the MP3::Tag page for details
Related
I've hit a wall and my google skills have this time failed me. I'm in the process of learning mojolicious to create a useful front end for a series of Perl scripts that I frequently use. I've got a long way through it but I'm stumped at (multiple) file uploads when the total number of files reaches 950.
Previously, I encountered the problem where- in multiple file uploads- files would begin to be uploaded, but once the filesize reached 16 mb the upload stopped. I fixed this by setting $ENV{MOJO_MAX_MESSAGE_SIZE} = 50000000000. However, this problem is different. To illustrate, this is part of my script where I try to grab the uploaded files:
my $files = $self->req->every_upload('localfiles');
for my $file ( #{$files} ) {
my $fileName = $file->filename =~ s/[^\w\d\.]+/_/gr;
$file->move_to("temporary_uploads/$fileName");
$self->app->log->debug("$fileName uploaded\n");
push #fileNames, $fileName;
};
say "FILES: ".scalar(#fileNames);
I apologise that it may be ugly. If I attempt to upload 949 files, my array #fileNames is populated correctly, but if I try to upload 950 files, my array ends up empty, and it seems as though $files is empty also. If anyone has any ideas or pointers to guide me to the solution I would be extremely grateful!
If I attempt to upload 949 files, my array #fileNames is populated correctly, but if I try to upload 950 files, my array ends up empty, and it seems as though $files is empty also.
That means the process is running out of file descriptors. In particular, the default for the Linux kernel is 1024:
For example, the kernel default for maximum number of file descriptors (ulimit -n) was 1024/1024 (soft, hard), and has been raised to 1024/4096 in Linux 2.6.39.
I'm using the following code to look through all files in a particular directory, and I'm getting some strange results. The point of the program is to do the following: I'm looking through a huge number (~7000+) of .mat files for each day between 6-20-2007 and 9-20-2007. What I'm looking to do is search through each of these folders and look at the .mat files, etc. However, for some reason I'm getting a 0x1 cell that doesn't make sense to me. Maybe someone with a better trained eye can see why?
jDate = strtok( dates(j).name, '.' ); % Or dates(j,1).name
tradeFolder = sprintf( 'TAQ Data\\trades unzipped\\%s.tar\\%s\\', jDate );
tradeFiles = what(tradeFolder);
tradeMat = tradeFiles.mat;
quoteFolder = sprintf( 'TAQ Data\\quotes unzipped\\%s.tar\\%s\\', jDate );
quoteFiles = what(quoteFolder);
quoteMat = quoteFiles.mat;
(I have excluded the beginnings of the file paths since it includes my name). Anyways, how the data is saved is this: I extracted each day's worth of data and saved it to the folders listed above. Inside trades unzipped, for instance, will be a folder 20070620.tar, and inside that folder will be another folder named 20070620, and inside that folder is over 7000 .mat files. So....how come I'm getting a 0x1 cell for the tradeFiles.mat?
If anyone can help I'd greatly appreciate it.
A few comments
Both sprintf lines you have (tradeFolder=... and quoteFolder=...) has two '%s' in the formatted string, while only one argument: jDate. This might cause undefined behavior.
It is better to use fullfile to concatenate paths and file names.
Although using what in this context is correct, you might want to double-check it using dir( fullfile( tradeFolder, '*.mat' ) );
It is best not to use i and j as variables in Matlab.
So me being the 'noob' that I am, being introduced to programming via Perl just recently, I'm still getting used to all of this. I have a .fasta file which I have to use, although I'm unsure if I'm able to open it, or if I have to work with it 'blindly', so to speak.
Anyway, the file that I have contains DNA sequences for three genes, written in this .fasta format.
Apparently it's something like this:
>label
sequence
>label
sequence
>label
sequence
My goal is to write a script to open and read the file, which I have gotten the hang of now, but I have to read each sequence, compute relative amounts of 'G' and 'C' within each sequence, and then I'm to write it to a TAB-delimited file the names of the genes, and their respective 'G' and 'C' content.
Would anyone be able to provide some guidance? I'm unsure what a TAB-delimited file is, and I'm still trying to figure out how to open a .fasta file to actually see the content. So far I've worked with .txt files which I can easily open, but not .fasta.
I apologise for sounding completely bewildered. I'd appreciate your patience. I'm not like you pros out there!!
I get that it's confusing, but you really should try to limit your question to one concrete problem, see https://stackoverflow.com/faq#questions
I have no idea what a ".fasta" file or 'G' and 'C' is.. but it probably doesn't matter.
Generally:
Open input file
Read and parse data. If it's in some strange format that you can't parse, go hunting on http://metacpan.org for a module to read it. If you're lucky someone has already done the hard part for you.
Compute whatever you're trying to compute
Print to screen (standard out) or another file.
A "TAB-delimite" file is a file with columns (think Excel) where each column is separated by the tab ("\t") character. As quick google or stackoverflow search would tell you..
Here is an approach using 'awk' utility which can be used from the command line. The following program is executed by specifying its path and using awk -f <path> <sequence file>
#NR>1 means only look at lines above 1 because you said the sequence starts on line 2
NR>1{
#this for-loop goes through all bases in the line and then performs operations below:
for (i=1;i<=length;i++)
#for each position encountered, the variable "total" is increased by 1 for total bases
total++
}
{
for (i=1;i<=length;i++)
#if the "substring" i.e. position in a line == c or g upper or lower (some bases are
#lowercase in some fasta files), it will carry out the following instructions:
if(substr($0,i,1)=="c" || substr($0,i,1)=="C")
#this increments the c count by one for every c or C encountered, the next if statement does
#the same thing for g and G:
c++; else
if(substr($0,i,1)=="g" || substr($0,i,1)=="G")
g++
}
END{
#this "END-block" prints the gene name and C, G content in percentage, separated by tabs
print "Gene name\tG content:\t"(100*g/total)"%\tC content:\t"(100*c/total)"%"
}
I am reading an .xls file using Spreadsheet::ParseExcel and was able to get data as is.
But,when reading an .xlsx file using Spreadsheet::XLSX, the read values are truncated.
E.g., 2.4578 in .xls and .xlsx file is read as 2.4578 and 2.45, respectively.
Please suggest why .xlsx file data is corrupted.
I created a simple workbook containing one sheet and only the value 2.4578 in A1 and ran the following script:
use Spreadsheet::XLSX;
my $excel = Spreadsheet::XLSX->new('Book1.xlsx');
my ($sheet) = #{ $excel->{Worksheet} };
print $sheet->{Cells}[0][0]{Val}, "\n";
Output:
C:\Temp> x
2.4578000000000002
So, in this simple case, everything seems to be OK.
If you can post a short, self-contained example that exhibits the problem and a small sample .xlsx file which we can look at, we would have a better chance of identifying the problem.
Try $cell->{Val} for the unformatted raw value instead of $cell->Value() for the Excel formatted value.
I have a MATLAB program that graphs some things and then outputs the graph to a file. If I run this program several times in the same directory, the file gets overwritten each time. How can I make it so the filename it outputs to changes...
I currently have this:
print -depsc myfigure
I have strings, rate and name, that I want to use, but can't get anything to work. If I can't use my strings, something random would be fine as well. Any way to do this?
Many thanks!
Name it with the current date and time:
print('-depsc2', ['prefix_' datestr(now, 30)])
run right now in PST, this creates a file called prefix_20100220T200733.eps. You can obviously change the prefix and/or the date format.
You can add current time to your file name. For example:
m=magic(10);
fh=figure, surf(m);
currenttime= datestr(now,'MMSSFFF');
print(['-f',num2str(fh)],'-depsc',['outputFileName_',currenttime,'.eps']);
This code checks if file exists, and if yes, adds a counter to its name.
filename = 'myfigure';
if exist([filename '.eps'],'file')
k=1;
while exist([filename '_' num2str(k) '.eps'], 'file')
k=k+1;
end
filename = [filename '_' num2str(k)]);
end
print('-depsc', filename);
Its simple. worked for me.
currenttime= datestr(now,'dd-mm-yy_HH:MM')
filename= ['graph' currenttime '.jpg']
print('-dpdf',filename)
Or any other file format you want to export. check print help.