Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Find a file with same name but different extension

by Jalcock501 (Sexton)
on Sep 24, 2013 at 13:10 UTC ( #1055485=perlquestion: print w/replies, xml ) Need Help??
Jalcock501 has asked for the wisdom of the Perl Monks concerning the following question:

Hey Guys

Another glorious day in scripting heaven, when all of a sudden a wild request appears. I need to create a script that checks two files together that have the same name but a different extension. i.e. (*.in) and (*.out)

So far I have managed to get the information I need from the *.in file but I have no idea how to check it against the information in the .out file.

Also I need to check that the file names(without the extension match)

This is my code so far:
use strict; my @files = <*.in>; for my $file (@files) { open my $read, '<', $file; open my $write, '>', "$file.log"; my $scid; my @lines; while(<$read>) { @lines = split('', $_); if($. == 3) { $scid = substr $_, 72,6; print $write "$scid\n"; } } #check where files match close($read); }
At the moment it only prints the unique identifier from the *.in the file to a seperate file to check that this is correct. The identifier is A00000 (one alpha 5 numeric) and is the 72nd bit offset from the 4th line, in the *.in file. However is 2nd line in and the 28th bit across in the *.out file. Please help!

Replies are listed 'Best First'.
Re: Find a file with same name but different extension
by toolic (Bishop) on Sep 24, 2013 at 14:06 UTC
    With lots of assumptions...
    use warnings; use strict; use File::Basename qw(fileparse); use File::Slurp qw(slurp); for my $fin (glob '*.in') { my $fout = (fileparse($fin, qr/\.in/))[0] . '.out'; my @ins = slurp($fin); my @outs = slurp($fout); my $id_in = (split /\s+/, $ins [3])[5]; my $id_out = (split /\s+/, $outs[1])[4] . '0'; if ($id_in eq $id_out) { print "match\n"; } else { print "no match\n"; } }

      This seems like a good place to use Tie::File instead of File::Slurp since you only need the first few lines of the files.

Re: Find a file with same name but different extension
by daxim (Chaplain) on Sep 24, 2013 at 13:21 UTC
    Please provide sample data to work with, your description is very unclear.
      Apologies here is some sample data.

      From in file:

      --ADMIN_RATEDATE=20131001 --ADMIN_SYSTYPE=M3 --QTS_LOB=PMC SPSPMBMBBB4000DNO101001 00750 314050010 T 1 + A044020 51 1 1 EL + + + 1 0101101000000011001101010001110000000220001010000101001000000000200012 +020001001000000011010010001010100350101030105500550100000015151200101 +105500104011505110000050001011100021100550030011001005100011000000000 +000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000 0010001100120010000100000010001001020000101100011100121010110100000000 +000000000001000000000000000022050520002000005000005005505000000000000 +050000005055000000000500500000000000000000500000000000000000000000000 +000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000006 0111100111212110201012210100020020001010010011010010110001111122200100 +001100001001111101111120001000505550055505005000050005000000500005005 +505505003055005000055050000000000550005000055550500000000500000000000 +000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000006 1010011002020001111001011000000000000000000000000000000000000000000000 +000000000000000000000000000000005005000000000535500005500000000000000 +000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000 |0010001401N01 YY0101000000YYYYYY010100 01201309192013091920130919N12011 KY2 6AB 0250 + Y 02PN 999 20001010106 0200 04 00 0000 +0 0811 00 GB N 0300030201309195204120102200309052003090520130918 05R005000 K +Y2 6 3 001200M 1 1 N N N + KY2 6AB + 062013091901NNNNN 062013091902NNNNN 062013091920NNNNN 101001002013091919531118MMP20010101FM 19531118 010000000000000001N +05NNN NNN 00 N + 1120130919E04049E Y 15201309193820060101N10010101

      And from the .out file:

      i zOffice Use : [11E2A7 A04402 AL 09134UM DU 9410 2200] h401PAR1 u3DATE = 01/03/2005 bPRICEY ROCKET # 1.00 u3For more details, u3Commenty goodness b+ #0.06 (6.00%) # 1.06 j1000010017 0109201301092013Test data 1N447 PA +R10 k5 NQ 2 00.00 N01010001.060000.060006.0000000 0000 1 + NYY01N00000.00N00000.00Y00000. +00 000001.06000000.06000006.00 q0001.060001.060001.060001.060001.060000000000000000000000000000000000 +000000NN00000 451000001.06000001.06000001.06000001.06000001.06 l01000 + + + + + + 04000000 +000000000000000000000000000000000000000000 a000.00000.00000.0000 Q401PAR1000 To Confirm Q401PAR1B001To Confirm Q401PAR1B002To Confirm Q401PAR1B003To Confirm Q401PAR1B004To Confirm Q401PAR1B005To Confirm Q401PAR1B006To Confirm Q401PAR1B007To Confirm Q401PAR1B008To Confirm Q401PAR1B009To Confirm Q401PAR1B010To Confirm
      As you can see 4 lines down(or this case right next the + on the 5 line here) you can see the id A04402 (the additional zero is a separate flag) and in the .out file second line down (the i one the first is intentional) 28 bits across is the id there A04402) I need to make sure these match. In this case both files are called and CLF17936.out

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1055485]
Approved by hdb
Front-paged by toolic
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2018-03-17 15:09 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (224 votes). Check out past polls.