300zxmuro has asked for the wisdom of the Perl Monks concerning the following question:
Howdy Monks, I need help with a tiny part of this code............. If you have input lines formatted like "x=y", write Perl code to swap all of them (for example, "y=x"). Fill in where commented in the code below
#!/usr/bin/perl use strict; use warnings; my $filein = .... my $fileout = ...; open(INFILE, $filein) || die "Can’t open input ’$filename’: $!\n"; open(OUTFILE, "> fileout") || die "Can’t open output ’$filename’: $!\n +"; while (my $input_line = <INFILE>) { chomp($input_line); my $output_line = ''; # FILL IN CODE HERE print OUTFILE "$output_line\n"; }
Here is a sample input file: Mary Smith = 345-78-9090 Joseph Alioto = 976-83-1234 Corresponding sample output file: 345-78-9090 = Mary Smith 976-83-1234 = Joseph Alioto You also may assume that both field1 and field2 do NOT contain any "="s.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Swap Input lines
by GrandFather (Saint) on Apr 19, 2012 at 03:34 UTC | |
|
Re: Swap Input lines
by AnomalousMonk (Archbishop) on Apr 19, 2012 at 04:16 UTC | |
|
Re: Swap Input lines
by jwkrahn (Abbot) on Apr 19, 2012 at 04:18 UTC | |
|
Re: Swap Input lines
by trizen (Hermit) on Apr 19, 2012 at 09:31 UTC | |
by brx (Pilgrim) on Apr 19, 2012 at 10:09 UTC | |
by trizen (Hermit) on Apr 19, 2012 at 10:20 UTC | |
by JavaFan (Canon) on Apr 19, 2012 at 10:22 UTC | |
|
Re: Swap Input lines
by aaron_baugher (Curate) on Apr 19, 2012 at 14:23 UTC | |
|
Re: Swap Input lines
by locked_user sundialsvc4 (Abbot) on Apr 19, 2012 at 13:13 UTC |