#!/usr/bin/perl -w -s ##########INPUT Sequence, concatenated into a single string########## #example of chomp . # unless(@ARGV==1) {die "please provide name of the file in the command line!!\n";} my$filename=$ARGV[0]; #takes filenname from input line my $outfile="chomp_example"; open(OUT, "> $outfile") or die "cannot open $outfile:$!"; #assigns filehandle IN to filename or dies my$seq=''; #assigns empty string my$line=''; MAIN: {open(IN, "< $filename") or die "cannot open $filename:$!"; #assigns filehandle IN to filename or dies while(defined($line=)){ chomp($line); $seq .= $line ; } close (IN); print "with chomp:\n$seq\n\n\n"; print OUT "with chomp:\n$seq\n\n\n"; $seq=''; #assigns empty string $line=''; open(IN, "< $filename") or die "cannot open $filename:$!"; while( defined($line=)){ $seq .= $line ; } close (IN); print "without chomp:\n$seq\n\n\n"; print OUT "without chomp:\n$seq\n\n\n"; $seq=''; #assigns empty string $line=''; open(IN, "< $filename") or die "cannot open $filename:$!"; while( defined($line=)){ $seq .= chomp($line); } close (IN); print "with chomp inadvertantly used as function:\n$seq\n\n\n"; print OUT "with chomp inadvertantly used as function:\n$seq\n\n\n"; $seq=''; #assigns empty string $line=''; open(IN, "< $filename") or die "cannot open $filename:$!"; my@input=; close (IN); print "without chomp using array:\n@input\n\n\n"; print OUT "without chomp using array:\n@input\n\n\n"; $seq=''; #assigns empty string $line=''; @input=(); open(IN, "< $filename") or die "cannot open $filename:$!"; @input=; foreach (@input) {chomp$_}; close (IN); print "with chomp using array:\n@input\n\n\n"; print OUT "with chomp using array:\n@input\n\n\n"; $seq=''; #assigns empty string $line=''; @input=(); open(IN, "< $filename") or die "cannot open $filename:$!"; @input=; foreach $line (@input) { $line =chomp$line;} close (IN); print "with chomp-erroniously used using array:\n@input\n\n\n"; print OUT "with chomp-erroniously used using array:\n@input\n\n\n"; $seq=''; #assigns empty string $line=''; @input=(); open(IN, "< $filename") or die "cannot open $filename:$!"; @input=; foreach (@input) {chomp$_}; close (IN); my $out = join ("",@input); print "with chomp using array\nand join:\n$out\n\n\n"; print OUT "with chomp using array\nand join:\n$out\n\n\n"; $seq=''; #assigns empty string $line=''; @input=(); open(IN, "< $filename") or die "cannot open $filename:$!"; @input=; foreach (@input) {chomp$_}; close (IN); $out = join ("\n",@input); print "with chomp using array\nand join with \\n:\n$out\n\n\n"; print OUT "with chomp using array\nand join with \\n:\n$out\n\n\n"; close (OUT); }