<?xml version='1.0'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:atom="http://www.w3.org/2005/Atom" >
<channel>
	<title><![CDATA[BOL: Reformat the file names with Perl]]></title>
	<link>https://bioinformaticsonline.com/snippets/view/34614/reformat-the-file-names-with-perl?</link>
	<atom:link href="https://bioinformaticsonline.com/snippets/view/34614/reformat-the-file-names-with-perl?" rel="self" type="application/rss+xml" />
	<description><![CDATA[]]></description>
	
	<item>
	<guid isPermaLink="true">https://bioinformaticsonline.com/snippets/view/34614/reformat-the-file-names-with-perl</guid>
	<pubDate>Tue, 12 Dec 2017 11:09:06 -0600</pubDate>
	<link>https://bioinformaticsonline.com/snippets/view/34614/reformat-the-file-names-with-perl</link>
	<title><![CDATA[Reformat the file names with Perl]]></title>
	<description><![CDATA[<code>#!/usr/bin/perl
use strict;
use warnings;
use File::Copy qw(copy);;

$| = 1;

my %hash;
my @files = glob &quot;*.scf&quot;;

if (!$ARGV[0]){ print  &quot;Table file needed\n USAGE: $0 table\n&quot;; exit;}

my $ifh = read_fh($ARGV[0]);
while (my $line = &lt;$ifh&gt;) {

    next if $line =~ /^#/;
    #next if $. == 1;
    my ($lichenName, $name, $code) = split /\s+/, $line;

    next unless defined $lichenName and defined $name
            and defined $code;

    $hash{$name}{sps}= $lichenName;
    $hash{$name}{code}= $code;
}
#Chec one by one
for (0..$#files){
  $files[$_] =~ s/\.scf$//;
  my @pName = split /\_/, $files[$_];
  next if ! $hash{$pName[0]}{sps} or !$hash{$pName[0]}{code};
  my $newName= &quot;$hash{$pName[0]}{sps}&quot;.&quot;_$pName[0]&quot;.&quot;_$hash{$pName[0]}{code}&quot;.&quot;_$pName[1]&quot;.&quot;.&quot;.&quot;scf&quot;;
	if ( -f &quot;$files[$_].scf&quot; ) {
	copy(&quot;$files[$_].scf&quot;, $newName) or die &quot;Copy failed: $!&quot;;
	}
}


sub read_fh {
    my $filename = shift @_;
    my $filehandle;
        open $filehandle, &quot;&lt;$filename&quot; or die $!;
    return $filehandle;
}</code>]]></description>
	<dc:creator>Jit</dc:creator>
</item>

</channel>
</rss>