Link to home
Start Free TrialLog in
Avatar of artofchobo
artofchobo

asked on

How to adhere to 8.3 naming conventions

Hi guys,
I'm a newbie in perl.
I would like to have some ideas on how to convert a text file with filenames, seperated by \n (newline) to become 8.3 format using perl.

Meaning to say that
salarytext.file becomes salary~1.fil (8.3 naming convention)
Basically, its should just be like DOS...
I need some tips....


Thanks
Regards,
chobo
Avatar of artofchobo
artofchobo

ASKER


So far, I have done

while(<>)
{
     m/w{1,8}/;
     $first = $&;
     m/\.\w{3}/;
     $second = $&;
     $filename = "$first"."$second";
}

#!/usr/bin/perl
$j = 1;
$i = 0;
$k = 0;
@freq = 0;
while(<>)
{
#      $first = substr($_, 0, 8);
      m/\w{1,8}/;
      $first = $&;
      m/\.\w{3}/;
      $second = $&;
      $filename = "$first"."$second\n";
      push @x, $filename;
}

for ($k = 0; $k < $#x+1; $k++)
{
      for ($i = $j; $i < $#x+1; $i++)
      {
#            print "$x[$i]";
            if ($x[$k] == $x[$i])
            {
                  $freq[$k] +=1;
                  transform($x[$i]);
            }
      }
      $j++;
}
print @x;

sub transform
{
      $trunc = shift();
      substr($trunc, 0, 6)."_freq[$k]";
      $x[$i]=$trunc;
}

This is what I have in mind right now... but its not working......
ASKER CERTIFIED SOLUTION
Avatar of HonorGod
HonorGod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks

Any particular reason for the 'B'?  I thought that I had gone above and beyond with sufficient information to warrent an 'A'.
Mis-click....
I dont mind giving better records.....

Sorry... I havent tried it out yet but I guess the code should work!.