in reply to Re: 32 Character limit
in thread 32 Character limit

Thanks for the replies. However I am not sure I understand. Isn't my code

if ($action eq '-e') { my @cryptedText = cryptText($key,$action,\@input); my $i = join("\n",@cryptedText); print $i; }

Only calling cryptText (my encrypt sub) one time? It is then joining the newline characters to the end, because when I didn't it would fail to encode properly. Maybe I am missing the boat here.. Please explain

Replies are listed 'Best First'.
Re^3: 32 Character limit
by ikegami (Patriarch) on Feb 09, 2011 at 21:33 UTC

    Isn't my code only calling cryptText (my encrypt sub) one time?

    No, once for each element in @$input.

    foreach my $text (@$input) { ... $text = encrypt($text,$key); ... }
      Alright thanks. Gonna be pretty busy over the next few days, but ill modify my code and post back my results at some point.
      Thanks, I have fixed the problem with the following code:
      #!/usr/bin/perl -w use strict; use warnings; use Crypt::Tea; if (@ARGV != 3) { print STDERR "Usage: $0 [-d|-e] [FILENAME] [KEY] \n"; exit 1; } if (($ARGV[0] ne '-d') && ($ARGV[0] ne '-e')) { print "Specify '-d' to decrypt or '-e' to encrypt\n"; exit 1; } my ($action, $file, $key) = @ARGV; my $input; { open (my $fh, '<', $file) or die $!; binmode($fh); local $/; $input = <$fh>; } if ($action eq '-e') { print encrypt($input,$key); } if ($action eq '-d') { print decrypt($input,$key); }
      Can someone explain the "my $input; { ... }" part. I am unfamiliar with this type of code. Is this shorthand for a function?
        Just like all the other curlies in your code, { ... } creates a lexical scope. This causes $fh to be freed when we're done with it and causes $/ to revert to its previous value once we're done with it.