in reply to validations in perl

Hello Ekanvitha9 and welcome to the Monastery

The x modifier can help make matches readable in code. With this modifier any whitespace is not compiled into the pattern, unless escaped using the \s class.

#!/usr/bin/perl -T; use strict; use warnings; my $password = 'a!1"a$234]5%}&<AcdEf^&B*#$")'; $password =~ /\A # start of string ( # start capture [ # start character class A-Z a-z _ # alpha letters (\w) 0-9 # numbers (\d) > & { } < \$ [ # specials \] ! " % ) ^ * # ] # end character class {28} # match exactly 28 characters ) # end capture \z # end of string /x; # match flags $password = $1 or die send_log('password_reset'); print "$password\n"; sub send_log{ my $log_type = shift; $log_type =~ s/\A([A-Za-z][A-Za-z0-9_]{7,20})\z/$1/ or die; if($log_type eq 'password_reset'){ print "The first part of a new password has been sent to\n", "your inbox. Call facilities on the internal line\n", "to recieve the next part. You will also recieve\n", "instructions for locating the pigeon wearing the\n", "last part.\n"; # exit( release_pigeon( ++$pc ) ); } exit; }

Hope this helps. To go back and see your earlier posts, with lots of good advice about this kind of thing, just click on the write ups number on your home node.


Replies are listed 'Best First'.
Re^2: validations in perl
by haukex (Archbishop) on Jul 17, 2019 at 17:09 UTC
    With this modifier any whitespace is not compiled into the pattern, unless escaped using the \s class.

    Nitpick: "A single /x tells the regular expression parser to ignore most whitespace that is neither backslashed nor within a bracketed character class." - from perlre (emphasis mine).