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

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); ... }

Replies are listed 'Best First'.
Re^4: 32 Character limit
by z662 (Initiate) on Feb 11, 2011 at 01:11 UTC
    Alright thanks. Gonna be pretty busy over the next few days, but ill modify my code and post back my results at some point.
Re^4: 32 Character limit
by z662 (Initiate) on Feb 15, 2011 at 23:50 UTC
    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.