in reply to Writing in reverse

What about this solution? # Two string of the SAME length? my $length; open( FILE1, "string1" ); open( FILE2, "string2" ); $string1 = <FILE1>; $string2 = <FILE2>; map { $a = substr($string1, $_, 1); $b = substr($string2, $_, 1); print "$b$a "; } reverse(0 .. length($string1) - 1);

Replies are listed 'Best First'.
RE: RE: Writing in reverse
by davorg (Chancellor) on Aug 01, 2000 at 14:11 UTC

    If you edit your node and put <CODE> ... </CODE> tags around the code then it will be far more legible and your <FILE1> and <FILE> expressions won't be interpeted as HTML tags.

    At the same time, you should probably consider checking the return value from the open function. I realise that this is just an example, but people will copy and paste it, so you should make it as safe as possible.

    --
    <http://www.dave.org.uk>

    European Perl Conference - Sept 22/24 2000, ICA, London
    <http://www.yapc.org/Europe/>
      I see your point. Thank you :)
RE: RE: Writing in reverse
by larsen (Parson) on Aug 01, 2000 at 14:10 UTC
    Excuse me for my badly formatted reply.
    I've missed to RTF.How To display...:>
    
    Here the piece of code I suggest:
    
    my $length;
    
    open( FILE1, "string1" );
    open( FILE2, "string2" );
    
    $string1 = <FILE1>;
    $string2 = <FILE2>;
    
    map {
    	$a = substr($string1, $_, 1);
    	$b = substr($string2, $_, 1);
    	print "$b$a ";
    } reverse(0 .. length($string1) - 1);