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

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?

Replies are listed 'Best First'.
Re^5: 32 Character limit
by ikegami (Patriarch) on Feb 16, 2011 at 00:51 UTC
    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.