Assigning several variables from request URL using regexes

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
4
down vote

favorite












I refactored some of my code:



Summary: This implementation works with PSGI/Plack. It gets the URL from $env->PATH_INFO and assigns a different variable according to the value in the URL with regex.



This approach can redirect users to an existing URL in the router system. It also remembers the last page the user visited and detects if the URL has a string with 10 digits (token). All this is done via session file.



The previous code:



my $app = sub 

my $env = shift;

my $form = $env->' Auth::Form.LoginForm';
my $token = $env->'psgix.session'token;
my $fromreferer = $env->PATH_INFO;

my $onfirstnameapp;
if ($fromreferer eq '/')
$onfirstnameapp = '';
$env->'psgix.session'equal_root = 'equal_root';

elsif(grep(/(nameappd11)/, $fromreferer))
$env->'psgix.session'greather_ten_digits = 'greather_ten_digits';
$onfirstnameapp = '/greather_ten_digits';

elsif(grep(/(nameappd10)/, $fromreferer))
$env->'psgix.session'equal_ten = 'equal_ten';
$onfirstnameapp = $1 if $fromreferer =~ /.:?(nameappd10)/?/;

else
$env->'psgix.session'not_root_notroute = 'not_root_notroute';
$onfirstnameapp = $fromreferer . '/not_root_notroute';


my $onlineafterAppurl = $1 if $fromreferer =~ /.:?nameappd+(/.*)/;
$env->'psgix.session'current_request = $onfirstnameapp;

if($env->'psgix.session'user_id)

my $get_old_token = $env->'psgix.session'old_token;
my $offtoken = $env->'psgix.session'offtoken;

my ($code) = $router->match($env->PATH_INFO);

if ( $onfirstnameapp ne $token )
$env->'psgix.session'no_token_equal = 'no_token_equal';
check_url_exist_inrouter($onlineafterAppurl);
#
if (grep(/$onlineafterAppurl/, @resulturlcheck) or
(grep(/(nameappd10)/, $offtoken) && $onlineafterAppurl eq '') )

delete $env->'psgix.session'offtoken if $onlineafterAppurl eq '';
$onlineafterAppurl = "/$handler" if $onlineafterAppurl eq '';

if( $onfirstnameapp eq $offtoken

;

return ["404", ["Content-Type" => "text/html"], ["Not Found, go to : <a href='/'>Home</a> " ] ] unless $code;
return $code->($env);


if ($fromreferer ne '/')

return ["401", ["Content-Type" => "text/html"],
[ $form ]
];


return ["404", ["Content-Type" => "text/html"], [ $form ]];

};


The current code refactory:



my $app = sub 

my $env = shift;

my @all_urls_names = @$env->all_urls_names;

my $router = Routerapp->new;

my %set = (
handler => $all_urls_names[0],
tk => '/' . $env->'psgix.session'token,
fromreferer => $env->PATH_INFO,
token => $env->'psgix.session'token,
form => $env->theform,
user => $env->'psgix.session'user_id,
offtoken_form => $env->'psgix.session'offtoken,
get_old_token_form => $env->'psgix.session'old_token,
);

my $onfirsnameapp;
my $onafterappurl //= ''; #here I set a empty value to avoid unitialized value

$onfirsnameapp = do
if ($setfromreferer eq '/') ''
elsif (grep(/(tappd11)/, $setfromreferer)) '/greather_ten_digits'
elsif (grep(/(tappd10)/, $setfromreferer)) $1 if $setfromreferer =~ /.:?(tappd10)/?/
else $setfromreferer . '/not_root_notroute'
;

my %add_sesion = (
equal_ten => sub $env->'psgix.session'equal_ten = 'equal_ten' if grep( /(tappd10)/, $onfirsnameapp ); ,
current_request => sub $env->'psgix.session'current_request = $onfirsnameapp; ,
no_tkn_equal => sub $env->'psgix.session'no_tkn_equal = 'no_tkn_equal'; ,
menus_router_off => sub $env->'psgix.session'menus_router_off = 'off work'; ,
);

$add_sesionequal_ten->();
$add_sesioncurrent_request->();

if($setuser)

my ($code) = $router->match($env->PATH_INFO);
if ( $setonfirsnameapp ne $settoken )
$onafterappurl = $1 if $setfromreferer =~ /.:?tappd+/(.*)/;

$add_sesionno_tkn_equal->();

if (grep(/$onafterappurl/, @all_urls_names)
or (grep(/(tappd10)/, $setofftoken_form)
&& $onafterappurl eq '')
)

; #here finish is not equal to token

return ["404", ["Content-Type" => "text/html"], ["Not Found, go to : <a href='/'>Home </a> " ] ] unless $code;
return $code->($env);


if ($setfromreferer ne '/')
return ["401", ["Content-Type" => "text/html"],
[ $setform ]
];


return ["404", ["Content-Type" => "text/html"], [ $setform ]];




Is my refactoring good enough?







share|improve this question





















  • I don't know what the technical definition of "good enough" would be, but it certainly appears to be much easier to read and maintain than what you started with.
    – chicks
    Jul 17 at 14:41










  • There are some typos in the variable names that you might want to fix. Unrelated but looks like Perl made the syntax highlighting choke.
    – yuri
    Jul 17 at 19:53






  • 1




    Did you post the entire file? It seems like there should be some use lines in there.
    – chicks
    Jul 19 at 16:21










  • Your old code never declared or assigned the Routerapp instance $router. We don't really need to know what it does, but in terms of refactored code it should still do the same, so it would be useful to see all relevant parts of the old code to make an assessment.
    – simbabque
    Jul 20 at 10:02
















up vote
4
down vote

favorite












I refactored some of my code:



Summary: This implementation works with PSGI/Plack. It gets the URL from $env->PATH_INFO and assigns a different variable according to the value in the URL with regex.



This approach can redirect users to an existing URL in the router system. It also remembers the last page the user visited and detects if the URL has a string with 10 digits (token). All this is done via session file.



The previous code:



my $app = sub 

my $env = shift;

my $form = $env->' Auth::Form.LoginForm';
my $token = $env->'psgix.session'token;
my $fromreferer = $env->PATH_INFO;

my $onfirstnameapp;
if ($fromreferer eq '/')
$onfirstnameapp = '';
$env->'psgix.session'equal_root = 'equal_root';

elsif(grep(/(nameappd11)/, $fromreferer))
$env->'psgix.session'greather_ten_digits = 'greather_ten_digits';
$onfirstnameapp = '/greather_ten_digits';

elsif(grep(/(nameappd10)/, $fromreferer))
$env->'psgix.session'equal_ten = 'equal_ten';
$onfirstnameapp = $1 if $fromreferer =~ /.:?(nameappd10)/?/;

else
$env->'psgix.session'not_root_notroute = 'not_root_notroute';
$onfirstnameapp = $fromreferer . '/not_root_notroute';


my $onlineafterAppurl = $1 if $fromreferer =~ /.:?nameappd+(/.*)/;
$env->'psgix.session'current_request = $onfirstnameapp;

if($env->'psgix.session'user_id)

my $get_old_token = $env->'psgix.session'old_token;
my $offtoken = $env->'psgix.session'offtoken;

my ($code) = $router->match($env->PATH_INFO);

if ( $onfirstnameapp ne $token )
$env->'psgix.session'no_token_equal = 'no_token_equal';
check_url_exist_inrouter($onlineafterAppurl);
#
if (grep(/$onlineafterAppurl/, @resulturlcheck) or
(grep(/(nameappd10)/, $offtoken) && $onlineafterAppurl eq '') )

delete $env->'psgix.session'offtoken if $onlineafterAppurl eq '';
$onlineafterAppurl = "/$handler" if $onlineafterAppurl eq '';

if( $onfirstnameapp eq $offtoken

;

return ["404", ["Content-Type" => "text/html"], ["Not Found, go to : <a href='/'>Home</a> " ] ] unless $code;
return $code->($env);


if ($fromreferer ne '/')

return ["401", ["Content-Type" => "text/html"],
[ $form ]
];


return ["404", ["Content-Type" => "text/html"], [ $form ]];

};


The current code refactory:



my $app = sub 

my $env = shift;

my @all_urls_names = @$env->all_urls_names;

my $router = Routerapp->new;

my %set = (
handler => $all_urls_names[0],
tk => '/' . $env->'psgix.session'token,
fromreferer => $env->PATH_INFO,
token => $env->'psgix.session'token,
form => $env->theform,
user => $env->'psgix.session'user_id,
offtoken_form => $env->'psgix.session'offtoken,
get_old_token_form => $env->'psgix.session'old_token,
);

my $onfirsnameapp;
my $onafterappurl //= ''; #here I set a empty value to avoid unitialized value

$onfirsnameapp = do
if ($setfromreferer eq '/') ''
elsif (grep(/(tappd11)/, $setfromreferer)) '/greather_ten_digits'
elsif (grep(/(tappd10)/, $setfromreferer)) $1 if $setfromreferer =~ /.:?(tappd10)/?/
else $setfromreferer . '/not_root_notroute'
;

my %add_sesion = (
equal_ten => sub $env->'psgix.session'equal_ten = 'equal_ten' if grep( /(tappd10)/, $onfirsnameapp ); ,
current_request => sub $env->'psgix.session'current_request = $onfirsnameapp; ,
no_tkn_equal => sub $env->'psgix.session'no_tkn_equal = 'no_tkn_equal'; ,
menus_router_off => sub $env->'psgix.session'menus_router_off = 'off work'; ,
);

$add_sesionequal_ten->();
$add_sesioncurrent_request->();

if($setuser)

my ($code) = $router->match($env->PATH_INFO);
if ( $setonfirsnameapp ne $settoken )
$onafterappurl = $1 if $setfromreferer =~ /.:?tappd+/(.*)/;

$add_sesionno_tkn_equal->();

if (grep(/$onafterappurl/, @all_urls_names)
or (grep(/(tappd10)/, $setofftoken_form)
&& $onafterappurl eq '')
)

; #here finish is not equal to token

return ["404", ["Content-Type" => "text/html"], ["Not Found, go to : <a href='/'>Home </a> " ] ] unless $code;
return $code->($env);


if ($setfromreferer ne '/')
return ["401", ["Content-Type" => "text/html"],
[ $setform ]
];


return ["404", ["Content-Type" => "text/html"], [ $setform ]];




Is my refactoring good enough?







share|improve this question





















  • I don't know what the technical definition of "good enough" would be, but it certainly appears to be much easier to read and maintain than what you started with.
    – chicks
    Jul 17 at 14:41










  • There are some typos in the variable names that you might want to fix. Unrelated but looks like Perl made the syntax highlighting choke.
    – yuri
    Jul 17 at 19:53






  • 1




    Did you post the entire file? It seems like there should be some use lines in there.
    – chicks
    Jul 19 at 16:21










  • Your old code never declared or assigned the Routerapp instance $router. We don't really need to know what it does, but in terms of refactored code it should still do the same, so it would be useful to see all relevant parts of the old code to make an assessment.
    – simbabque
    Jul 20 at 10:02












up vote
4
down vote

favorite









up vote
4
down vote

favorite











I refactored some of my code:



Summary: This implementation works with PSGI/Plack. It gets the URL from $env->PATH_INFO and assigns a different variable according to the value in the URL with regex.



This approach can redirect users to an existing URL in the router system. It also remembers the last page the user visited and detects if the URL has a string with 10 digits (token). All this is done via session file.



The previous code:



my $app = sub 

my $env = shift;

my $form = $env->' Auth::Form.LoginForm';
my $token = $env->'psgix.session'token;
my $fromreferer = $env->PATH_INFO;

my $onfirstnameapp;
if ($fromreferer eq '/')
$onfirstnameapp = '';
$env->'psgix.session'equal_root = 'equal_root';

elsif(grep(/(nameappd11)/, $fromreferer))
$env->'psgix.session'greather_ten_digits = 'greather_ten_digits';
$onfirstnameapp = '/greather_ten_digits';

elsif(grep(/(nameappd10)/, $fromreferer))
$env->'psgix.session'equal_ten = 'equal_ten';
$onfirstnameapp = $1 if $fromreferer =~ /.:?(nameappd10)/?/;

else
$env->'psgix.session'not_root_notroute = 'not_root_notroute';
$onfirstnameapp = $fromreferer . '/not_root_notroute';


my $onlineafterAppurl = $1 if $fromreferer =~ /.:?nameappd+(/.*)/;
$env->'psgix.session'current_request = $onfirstnameapp;

if($env->'psgix.session'user_id)

my $get_old_token = $env->'psgix.session'old_token;
my $offtoken = $env->'psgix.session'offtoken;

my ($code) = $router->match($env->PATH_INFO);

if ( $onfirstnameapp ne $token )
$env->'psgix.session'no_token_equal = 'no_token_equal';
check_url_exist_inrouter($onlineafterAppurl);
#
if (grep(/$onlineafterAppurl/, @resulturlcheck) or
(grep(/(nameappd10)/, $offtoken) && $onlineafterAppurl eq '') )

delete $env->'psgix.session'offtoken if $onlineafterAppurl eq '';
$onlineafterAppurl = "/$handler" if $onlineafterAppurl eq '';

if( $onfirstnameapp eq $offtoken

;

return ["404", ["Content-Type" => "text/html"], ["Not Found, go to : <a href='/'>Home</a> " ] ] unless $code;
return $code->($env);


if ($fromreferer ne '/')

return ["401", ["Content-Type" => "text/html"],
[ $form ]
];


return ["404", ["Content-Type" => "text/html"], [ $form ]];

};


The current code refactory:



my $app = sub 

my $env = shift;

my @all_urls_names = @$env->all_urls_names;

my $router = Routerapp->new;

my %set = (
handler => $all_urls_names[0],
tk => '/' . $env->'psgix.session'token,
fromreferer => $env->PATH_INFO,
token => $env->'psgix.session'token,
form => $env->theform,
user => $env->'psgix.session'user_id,
offtoken_form => $env->'psgix.session'offtoken,
get_old_token_form => $env->'psgix.session'old_token,
);

my $onfirsnameapp;
my $onafterappurl //= ''; #here I set a empty value to avoid unitialized value

$onfirsnameapp = do
if ($setfromreferer eq '/') ''
elsif (grep(/(tappd11)/, $setfromreferer)) '/greather_ten_digits'
elsif (grep(/(tappd10)/, $setfromreferer)) $1 if $setfromreferer =~ /.:?(tappd10)/?/
else $setfromreferer . '/not_root_notroute'
;

my %add_sesion = (
equal_ten => sub $env->'psgix.session'equal_ten = 'equal_ten' if grep( /(tappd10)/, $onfirsnameapp ); ,
current_request => sub $env->'psgix.session'current_request = $onfirsnameapp; ,
no_tkn_equal => sub $env->'psgix.session'no_tkn_equal = 'no_tkn_equal'; ,
menus_router_off => sub $env->'psgix.session'menus_router_off = 'off work'; ,
);

$add_sesionequal_ten->();
$add_sesioncurrent_request->();

if($setuser)

my ($code) = $router->match($env->PATH_INFO);
if ( $setonfirsnameapp ne $settoken )
$onafterappurl = $1 if $setfromreferer =~ /.:?tappd+/(.*)/;

$add_sesionno_tkn_equal->();

if (grep(/$onafterappurl/, @all_urls_names)
or (grep(/(tappd10)/, $setofftoken_form)
&& $onafterappurl eq '')
)

; #here finish is not equal to token

return ["404", ["Content-Type" => "text/html"], ["Not Found, go to : <a href='/'>Home </a> " ] ] unless $code;
return $code->($env);


if ($setfromreferer ne '/')
return ["401", ["Content-Type" => "text/html"],
[ $setform ]
];


return ["404", ["Content-Type" => "text/html"], [ $setform ]];




Is my refactoring good enough?







share|improve this question













I refactored some of my code:



Summary: This implementation works with PSGI/Plack. It gets the URL from $env->PATH_INFO and assigns a different variable according to the value in the URL with regex.



This approach can redirect users to an existing URL in the router system. It also remembers the last page the user visited and detects if the URL has a string with 10 digits (token). All this is done via session file.



The previous code:



my $app = sub 

my $env = shift;

my $form = $env->' Auth::Form.LoginForm';
my $token = $env->'psgix.session'token;
my $fromreferer = $env->PATH_INFO;

my $onfirstnameapp;
if ($fromreferer eq '/')
$onfirstnameapp = '';
$env->'psgix.session'equal_root = 'equal_root';

elsif(grep(/(nameappd11)/, $fromreferer))
$env->'psgix.session'greather_ten_digits = 'greather_ten_digits';
$onfirstnameapp = '/greather_ten_digits';

elsif(grep(/(nameappd10)/, $fromreferer))
$env->'psgix.session'equal_ten = 'equal_ten';
$onfirstnameapp = $1 if $fromreferer =~ /.:?(nameappd10)/?/;

else
$env->'psgix.session'not_root_notroute = 'not_root_notroute';
$onfirstnameapp = $fromreferer . '/not_root_notroute';


my $onlineafterAppurl = $1 if $fromreferer =~ /.:?nameappd+(/.*)/;
$env->'psgix.session'current_request = $onfirstnameapp;

if($env->'psgix.session'user_id)

my $get_old_token = $env->'psgix.session'old_token;
my $offtoken = $env->'psgix.session'offtoken;

my ($code) = $router->match($env->PATH_INFO);

if ( $onfirstnameapp ne $token )
$env->'psgix.session'no_token_equal = 'no_token_equal';
check_url_exist_inrouter($onlineafterAppurl);
#
if (grep(/$onlineafterAppurl/, @resulturlcheck) or
(grep(/(nameappd10)/, $offtoken) && $onlineafterAppurl eq '') )

delete $env->'psgix.session'offtoken if $onlineafterAppurl eq '';
$onlineafterAppurl = "/$handler" if $onlineafterAppurl eq '';

if( $onfirstnameapp eq $offtoken

;

return ["404", ["Content-Type" => "text/html"], ["Not Found, go to : <a href='/'>Home</a> " ] ] unless $code;
return $code->($env);


if ($fromreferer ne '/')

return ["401", ["Content-Type" => "text/html"],
[ $form ]
];


return ["404", ["Content-Type" => "text/html"], [ $form ]];

};


The current code refactory:



my $app = sub 

my $env = shift;

my @all_urls_names = @$env->all_urls_names;

my $router = Routerapp->new;

my %set = (
handler => $all_urls_names[0],
tk => '/' . $env->'psgix.session'token,
fromreferer => $env->PATH_INFO,
token => $env->'psgix.session'token,
form => $env->theform,
user => $env->'psgix.session'user_id,
offtoken_form => $env->'psgix.session'offtoken,
get_old_token_form => $env->'psgix.session'old_token,
);

my $onfirsnameapp;
my $onafterappurl //= ''; #here I set a empty value to avoid unitialized value

$onfirsnameapp = do
if ($setfromreferer eq '/') ''
elsif (grep(/(tappd11)/, $setfromreferer)) '/greather_ten_digits'
elsif (grep(/(tappd10)/, $setfromreferer)) $1 if $setfromreferer =~ /.:?(tappd10)/?/
else $setfromreferer . '/not_root_notroute'
;

my %add_sesion = (
equal_ten => sub $env->'psgix.session'equal_ten = 'equal_ten' if grep( /(tappd10)/, $onfirsnameapp ); ,
current_request => sub $env->'psgix.session'current_request = $onfirsnameapp; ,
no_tkn_equal => sub $env->'psgix.session'no_tkn_equal = 'no_tkn_equal'; ,
menus_router_off => sub $env->'psgix.session'menus_router_off = 'off work'; ,
);

$add_sesionequal_ten->();
$add_sesioncurrent_request->();

if($setuser)

my ($code) = $router->match($env->PATH_INFO);
if ( $setonfirsnameapp ne $settoken )
$onafterappurl = $1 if $setfromreferer =~ /.:?tappd+/(.*)/;

$add_sesionno_tkn_equal->();

if (grep(/$onafterappurl/, @all_urls_names)
or (grep(/(tappd10)/, $setofftoken_form)
&& $onafterappurl eq '')
)

; #here finish is not equal to token

return ["404", ["Content-Type" => "text/html"], ["Not Found, go to : <a href='/'>Home </a> " ] ] unless $code;
return $code->($env);


if ($setfromreferer ne '/')
return ["401", ["Content-Type" => "text/html"],
[ $setform ]
];


return ["404", ["Content-Type" => "text/html"], [ $setform ]];




Is my refactoring good enough?









share|improve this question












share|improve this question




share|improve this question








edited Jul 16 at 18:39









yuri

3,3872832




3,3872832









asked Jul 16 at 16:02









The nothing

211




211











  • I don't know what the technical definition of "good enough" would be, but it certainly appears to be much easier to read and maintain than what you started with.
    – chicks
    Jul 17 at 14:41










  • There are some typos in the variable names that you might want to fix. Unrelated but looks like Perl made the syntax highlighting choke.
    – yuri
    Jul 17 at 19:53






  • 1




    Did you post the entire file? It seems like there should be some use lines in there.
    – chicks
    Jul 19 at 16:21










  • Your old code never declared or assigned the Routerapp instance $router. We don't really need to know what it does, but in terms of refactored code it should still do the same, so it would be useful to see all relevant parts of the old code to make an assessment.
    – simbabque
    Jul 20 at 10:02
















  • I don't know what the technical definition of "good enough" would be, but it certainly appears to be much easier to read and maintain than what you started with.
    – chicks
    Jul 17 at 14:41










  • There are some typos in the variable names that you might want to fix. Unrelated but looks like Perl made the syntax highlighting choke.
    – yuri
    Jul 17 at 19:53






  • 1




    Did you post the entire file? It seems like there should be some use lines in there.
    – chicks
    Jul 19 at 16:21










  • Your old code never declared or assigned the Routerapp instance $router. We don't really need to know what it does, but in terms of refactored code it should still do the same, so it would be useful to see all relevant parts of the old code to make an assessment.
    – simbabque
    Jul 20 at 10:02















I don't know what the technical definition of "good enough" would be, but it certainly appears to be much easier to read and maintain than what you started with.
– chicks
Jul 17 at 14:41




I don't know what the technical definition of "good enough" would be, but it certainly appears to be much easier to read and maintain than what you started with.
– chicks
Jul 17 at 14:41












There are some typos in the variable names that you might want to fix. Unrelated but looks like Perl made the syntax highlighting choke.
– yuri
Jul 17 at 19:53




There are some typos in the variable names that you might want to fix. Unrelated but looks like Perl made the syntax highlighting choke.
– yuri
Jul 17 at 19:53




1




1




Did you post the entire file? It seems like there should be some use lines in there.
– chicks
Jul 19 at 16:21




Did you post the entire file? It seems like there should be some use lines in there.
– chicks
Jul 19 at 16:21












Your old code never declared or assigned the Routerapp instance $router. We don't really need to know what it does, but in terms of refactored code it should still do the same, so it would be useful to see all relevant parts of the old code to make an assessment.
– simbabque
Jul 20 at 10:02




Your old code never declared or assigned the Routerapp instance $router. We don't really need to know what it does, but in terms of refactored code it should still do the same, so it would be useful to see all relevant parts of the old code to make an assessment.
– simbabque
Jul 20 at 10:02










2 Answers
2






active

oldest

votes

















up vote
1
down vote













I'm not really comparing before and after. Without seeing the data that comes in that's a bit hard. Instead I'll focus on the new code.



In general, a lot of your variables could benefit from clearer naming. If you use more than one word for a name, which is good, use underscores _ to separate them, like $on_first_name_app. You've already done this in a couple of places. Being consistent is important to make code more readable.



There are also quite a few typos in your variable names and comments. When you fix those, make sure not to fix the typos in the URLs as those have been there before, and you have to retain existing behavior when you refactor code.




  • regarding $onfirsnameapp:



    It's best practice in Perl to declare variables as late as possible. You can move the my $onfirsnameapp down to where you assign it.




    elsif (grep(/(tappd11)/, $setfromreferer)) 


    '/greather_ten_digits'




    You seem to be using grep for a single scalar regular expression match. $setfromreferrer is just a string, not an array, so grep doesn't really make sense. You also don't need the capture group there.



    You can shorten this to:



    elsif ( $setfromreferer =~ m/tappd11/ ) '/greather_ten_digits' 


    Similarly in the next one you can also remove the grep and the capture group. In addition, you can use a different delimiter than // with m to get rid of the backslash escape.



    elsif ( $setfromreferer =~ m/tappd10/ ) 
    $1 if $setfromreferer =~ m.:?(tappd10)/?;



    This grep thing keeps appearing throughout the code.




  • my $onafterappurl //= '';



    The //= assignment is useless. A new lexical variable will always be undef unless you assign it something. If you want it to be an empty string, just say so.



    my $onafterappurl = q;


    I prefer q over '' because it's clearer that it means an empty string.




  • %add_sesion (it's session with two s).



    I don't understand why this is a dispatch table. None of this is complicated, and each of them are only used once. This is useless and the code could just be written as code at the time where it's called.



Besides these points, the code is fine. If you pick better names and add some comments as to why things are done, I would like it a lot more though.



When you write comments, try to explain the business logic decisions. The code already clearly shows that a value is assigned an empty string because it's used as a string later. But some of deeply nested decisions where the redirect is issued would really benefit from explaining why this happens.



Finally, when you refactor code, always work with unit tests to be on the safe side. Look at Plack::Test if you haven't to build some tests for this. You can also use a combination of Test::WWW::Mechanize and LWP::Protocol::PSGI if you feel more comfortable with having a $mech object in your tests.






share|improve this answer




























    up vote
    1
    down vote













    First, install perltidy and run it against your code until you get used to looking at well formatted code and type it that way.



    Second, names are really, really important. Names for functions and variables should be readable (use camel case or snake case to break up long names, but be consistent) and descriptive. Make sure the names are spelled correctly. Don't use names like greater_than_ten. The rule may change and you start caring about URLs with more than 12 or 8 digits. Instead name it for the meaning. Maybe something $url_with_token



    You have logic and effects all mixed up and spread out. Instead of setting a variable at line 10 and then maybe resetting at line 30 so that you can use it at line 90, (line numbers are hypothetical here), either do all your input analysis in one place and set up a packet of info you need later, OR analyze your data and take action on within a few lines.



    Look for repetition and factor it into subroutines.



    Putting a bunch of related (or not) variables into a hash doesn't really do much except add syntax to access or mutate the values.



    Let's analyze your code. It does one of five things with all inputs:



    1. Runs some PSGI application code

    2. Redirects to another URL

    3. Returns HTTP 401 status: Unauthorized.

    4. Returns HTTP 404 status: Not found with two different response bodies.

    Well, 404 with the form data (whatever that is) is your fallback case. If you have a user_id then you redirect, run code if you have it, or 404. And you 401 if you your referrer data looks fishy.



    So your app boils down to:



    sub app 
    my $env = shift;

    return
    get_user_id($env) ? run_app_or_redirect($env)
    : is_request_authorized($env) ? FILE_NOT_FOUND( get_form($env) )
    : UNAUTHORIZED( get_form($env) )
    ;



    Huh, wow, checking auth only for not found? That's probably a bug. For now, let's forge ahead.



    The FILE_NOT_FOUND and other error subs just look like this:



    sub FILE_NOT_FOUND 
    my @body = @_;
    my $default_message = "Not Found, go to : <a href='/'>Home </a> ";

    return ["404", ["Content-Type" => "text/html"], [ @body ? @body : $default_message ]];



    The getters that fetch values from $env are like this:



    sub get_user 
    my $env = shift;
    return $env->'psgix.session'user_id // '';



    Checking request authorization is combines the lookup when you set fromreferer and the spot where you check it to maybe return an error message.



    sub is_request_authorized 
    my $env = shift;
    return '/' eq $env->PATH_INFO;



    The tricky one is, of course, run_app_or_redirect(). I'm not going to work that all out for you. You should be able to do that yourself and probably better than I can since you know the problem domain. Just break the code into sections. First decide which thing you are going to do, and then collect the information needed to do it. You may even wish to make the main sub look like:



    sub app 


    I hope this helps.






    share|improve this answer





















      Your Answer




      StackExchange.ifUsing("editor", function ()
      return StackExchange.using("mathjaxEditing", function ()
      StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
      StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
      );
      );
      , "mathjax-editing");

      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "196"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: false,
      noModals: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );








       

      draft saved


      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f199601%2fassigning-several-variables-from-request-url-using-regexes%23new-answer', 'question_page');

      );

      Post as a guest






























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      1
      down vote













      I'm not really comparing before and after. Without seeing the data that comes in that's a bit hard. Instead I'll focus on the new code.



      In general, a lot of your variables could benefit from clearer naming. If you use more than one word for a name, which is good, use underscores _ to separate them, like $on_first_name_app. You've already done this in a couple of places. Being consistent is important to make code more readable.



      There are also quite a few typos in your variable names and comments. When you fix those, make sure not to fix the typos in the URLs as those have been there before, and you have to retain existing behavior when you refactor code.




      • regarding $onfirsnameapp:



        It's best practice in Perl to declare variables as late as possible. You can move the my $onfirsnameapp down to where you assign it.




        elsif (grep(/(tappd11)/, $setfromreferer)) 


        '/greather_ten_digits'




        You seem to be using grep for a single scalar regular expression match. $setfromreferrer is just a string, not an array, so grep doesn't really make sense. You also don't need the capture group there.



        You can shorten this to:



        elsif ( $setfromreferer =~ m/tappd11/ ) '/greather_ten_digits' 


        Similarly in the next one you can also remove the grep and the capture group. In addition, you can use a different delimiter than // with m to get rid of the backslash escape.



        elsif ( $setfromreferer =~ m/tappd10/ ) 
        $1 if $setfromreferer =~ m.:?(tappd10)/?;



        This grep thing keeps appearing throughout the code.




      • my $onafterappurl //= '';



        The //= assignment is useless. A new lexical variable will always be undef unless you assign it something. If you want it to be an empty string, just say so.



        my $onafterappurl = q;


        I prefer q over '' because it's clearer that it means an empty string.




      • %add_sesion (it's session with two s).



        I don't understand why this is a dispatch table. None of this is complicated, and each of them are only used once. This is useless and the code could just be written as code at the time where it's called.



      Besides these points, the code is fine. If you pick better names and add some comments as to why things are done, I would like it a lot more though.



      When you write comments, try to explain the business logic decisions. The code already clearly shows that a value is assigned an empty string because it's used as a string later. But some of deeply nested decisions where the redirect is issued would really benefit from explaining why this happens.



      Finally, when you refactor code, always work with unit tests to be on the safe side. Look at Plack::Test if you haven't to build some tests for this. You can also use a combination of Test::WWW::Mechanize and LWP::Protocol::PSGI if you feel more comfortable with having a $mech object in your tests.






      share|improve this answer

























        up vote
        1
        down vote













        I'm not really comparing before and after. Without seeing the data that comes in that's a bit hard. Instead I'll focus on the new code.



        In general, a lot of your variables could benefit from clearer naming. If you use more than one word for a name, which is good, use underscores _ to separate them, like $on_first_name_app. You've already done this in a couple of places. Being consistent is important to make code more readable.



        There are also quite a few typos in your variable names and comments. When you fix those, make sure not to fix the typos in the URLs as those have been there before, and you have to retain existing behavior when you refactor code.




        • regarding $onfirsnameapp:



          It's best practice in Perl to declare variables as late as possible. You can move the my $onfirsnameapp down to where you assign it.




          elsif (grep(/(tappd11)/, $setfromreferer)) 


          '/greather_ten_digits'




          You seem to be using grep for a single scalar regular expression match. $setfromreferrer is just a string, not an array, so grep doesn't really make sense. You also don't need the capture group there.



          You can shorten this to:



          elsif ( $setfromreferer =~ m/tappd11/ ) '/greather_ten_digits' 


          Similarly in the next one you can also remove the grep and the capture group. In addition, you can use a different delimiter than // with m to get rid of the backslash escape.



          elsif ( $setfromreferer =~ m/tappd10/ ) 
          $1 if $setfromreferer =~ m.:?(tappd10)/?;



          This grep thing keeps appearing throughout the code.




        • my $onafterappurl //= '';



          The //= assignment is useless. A new lexical variable will always be undef unless you assign it something. If you want it to be an empty string, just say so.



          my $onafterappurl = q;


          I prefer q over '' because it's clearer that it means an empty string.




        • %add_sesion (it's session with two s).



          I don't understand why this is a dispatch table. None of this is complicated, and each of them are only used once. This is useless and the code could just be written as code at the time where it's called.



        Besides these points, the code is fine. If you pick better names and add some comments as to why things are done, I would like it a lot more though.



        When you write comments, try to explain the business logic decisions. The code already clearly shows that a value is assigned an empty string because it's used as a string later. But some of deeply nested decisions where the redirect is issued would really benefit from explaining why this happens.



        Finally, when you refactor code, always work with unit tests to be on the safe side. Look at Plack::Test if you haven't to build some tests for this. You can also use a combination of Test::WWW::Mechanize and LWP::Protocol::PSGI if you feel more comfortable with having a $mech object in your tests.






        share|improve this answer























          up vote
          1
          down vote










          up vote
          1
          down vote









          I'm not really comparing before and after. Without seeing the data that comes in that's a bit hard. Instead I'll focus on the new code.



          In general, a lot of your variables could benefit from clearer naming. If you use more than one word for a name, which is good, use underscores _ to separate them, like $on_first_name_app. You've already done this in a couple of places. Being consistent is important to make code more readable.



          There are also quite a few typos in your variable names and comments. When you fix those, make sure not to fix the typos in the URLs as those have been there before, and you have to retain existing behavior when you refactor code.




          • regarding $onfirsnameapp:



            It's best practice in Perl to declare variables as late as possible. You can move the my $onfirsnameapp down to where you assign it.




            elsif (grep(/(tappd11)/, $setfromreferer)) 


            '/greather_ten_digits'




            You seem to be using grep for a single scalar regular expression match. $setfromreferrer is just a string, not an array, so grep doesn't really make sense. You also don't need the capture group there.



            You can shorten this to:



            elsif ( $setfromreferer =~ m/tappd11/ ) '/greather_ten_digits' 


            Similarly in the next one you can also remove the grep and the capture group. In addition, you can use a different delimiter than // with m to get rid of the backslash escape.



            elsif ( $setfromreferer =~ m/tappd10/ ) 
            $1 if $setfromreferer =~ m.:?(tappd10)/?;



            This grep thing keeps appearing throughout the code.




          • my $onafterappurl //= '';



            The //= assignment is useless. A new lexical variable will always be undef unless you assign it something. If you want it to be an empty string, just say so.



            my $onafterappurl = q;


            I prefer q over '' because it's clearer that it means an empty string.




          • %add_sesion (it's session with two s).



            I don't understand why this is a dispatch table. None of this is complicated, and each of them are only used once. This is useless and the code could just be written as code at the time where it's called.



          Besides these points, the code is fine. If you pick better names and add some comments as to why things are done, I would like it a lot more though.



          When you write comments, try to explain the business logic decisions. The code already clearly shows that a value is assigned an empty string because it's used as a string later. But some of deeply nested decisions where the redirect is issued would really benefit from explaining why this happens.



          Finally, when you refactor code, always work with unit tests to be on the safe side. Look at Plack::Test if you haven't to build some tests for this. You can also use a combination of Test::WWW::Mechanize and LWP::Protocol::PSGI if you feel more comfortable with having a $mech object in your tests.






          share|improve this answer













          I'm not really comparing before and after. Without seeing the data that comes in that's a bit hard. Instead I'll focus on the new code.



          In general, a lot of your variables could benefit from clearer naming. If you use more than one word for a name, which is good, use underscores _ to separate them, like $on_first_name_app. You've already done this in a couple of places. Being consistent is important to make code more readable.



          There are also quite a few typos in your variable names and comments. When you fix those, make sure not to fix the typos in the URLs as those have been there before, and you have to retain existing behavior when you refactor code.




          • regarding $onfirsnameapp:



            It's best practice in Perl to declare variables as late as possible. You can move the my $onfirsnameapp down to where you assign it.




            elsif (grep(/(tappd11)/, $setfromreferer)) 


            '/greather_ten_digits'




            You seem to be using grep for a single scalar regular expression match. $setfromreferrer is just a string, not an array, so grep doesn't really make sense. You also don't need the capture group there.



            You can shorten this to:



            elsif ( $setfromreferer =~ m/tappd11/ ) '/greather_ten_digits' 


            Similarly in the next one you can also remove the grep and the capture group. In addition, you can use a different delimiter than // with m to get rid of the backslash escape.



            elsif ( $setfromreferer =~ m/tappd10/ ) 
            $1 if $setfromreferer =~ m.:?(tappd10)/?;



            This grep thing keeps appearing throughout the code.




          • my $onafterappurl //= '';



            The //= assignment is useless. A new lexical variable will always be undef unless you assign it something. If you want it to be an empty string, just say so.



            my $onafterappurl = q;


            I prefer q over '' because it's clearer that it means an empty string.




          • %add_sesion (it's session with two s).



            I don't understand why this is a dispatch table. None of this is complicated, and each of them are only used once. This is useless and the code could just be written as code at the time where it's called.



          Besides these points, the code is fine. If you pick better names and add some comments as to why things are done, I would like it a lot more though.



          When you write comments, try to explain the business logic decisions. The code already clearly shows that a value is assigned an empty string because it's used as a string later. But some of deeply nested decisions where the redirect is issued would really benefit from explaining why this happens.



          Finally, when you refactor code, always work with unit tests to be on the safe side. Look at Plack::Test if you haven't to build some tests for this. You can also use a combination of Test::WWW::Mechanize and LWP::Protocol::PSGI if you feel more comfortable with having a $mech object in your tests.







          share|improve this answer













          share|improve this answer



          share|improve this answer











          answered Jul 20 at 10:35









          simbabque

          933710




          933710






















              up vote
              1
              down vote













              First, install perltidy and run it against your code until you get used to looking at well formatted code and type it that way.



              Second, names are really, really important. Names for functions and variables should be readable (use camel case or snake case to break up long names, but be consistent) and descriptive. Make sure the names are spelled correctly. Don't use names like greater_than_ten. The rule may change and you start caring about URLs with more than 12 or 8 digits. Instead name it for the meaning. Maybe something $url_with_token



              You have logic and effects all mixed up and spread out. Instead of setting a variable at line 10 and then maybe resetting at line 30 so that you can use it at line 90, (line numbers are hypothetical here), either do all your input analysis in one place and set up a packet of info you need later, OR analyze your data and take action on within a few lines.



              Look for repetition and factor it into subroutines.



              Putting a bunch of related (or not) variables into a hash doesn't really do much except add syntax to access or mutate the values.



              Let's analyze your code. It does one of five things with all inputs:



              1. Runs some PSGI application code

              2. Redirects to another URL

              3. Returns HTTP 401 status: Unauthorized.

              4. Returns HTTP 404 status: Not found with two different response bodies.

              Well, 404 with the form data (whatever that is) is your fallback case. If you have a user_id then you redirect, run code if you have it, or 404. And you 401 if you your referrer data looks fishy.



              So your app boils down to:



              sub app 
              my $env = shift;

              return
              get_user_id($env) ? run_app_or_redirect($env)
              : is_request_authorized($env) ? FILE_NOT_FOUND( get_form($env) )
              : UNAUTHORIZED( get_form($env) )
              ;



              Huh, wow, checking auth only for not found? That's probably a bug. For now, let's forge ahead.



              The FILE_NOT_FOUND and other error subs just look like this:



              sub FILE_NOT_FOUND 
              my @body = @_;
              my $default_message = "Not Found, go to : <a href='/'>Home </a> ";

              return ["404", ["Content-Type" => "text/html"], [ @body ? @body : $default_message ]];



              The getters that fetch values from $env are like this:



              sub get_user 
              my $env = shift;
              return $env->'psgix.session'user_id // '';



              Checking request authorization is combines the lookup when you set fromreferer and the spot where you check it to maybe return an error message.



              sub is_request_authorized 
              my $env = shift;
              return '/' eq $env->PATH_INFO;



              The tricky one is, of course, run_app_or_redirect(). I'm not going to work that all out for you. You should be able to do that yourself and probably better than I can since you know the problem domain. Just break the code into sections. First decide which thing you are going to do, and then collect the information needed to do it. You may even wish to make the main sub look like:



              sub app 


              I hope this helps.






              share|improve this answer

























                up vote
                1
                down vote













                First, install perltidy and run it against your code until you get used to looking at well formatted code and type it that way.



                Second, names are really, really important. Names for functions and variables should be readable (use camel case or snake case to break up long names, but be consistent) and descriptive. Make sure the names are spelled correctly. Don't use names like greater_than_ten. The rule may change and you start caring about URLs with more than 12 or 8 digits. Instead name it for the meaning. Maybe something $url_with_token



                You have logic and effects all mixed up and spread out. Instead of setting a variable at line 10 and then maybe resetting at line 30 so that you can use it at line 90, (line numbers are hypothetical here), either do all your input analysis in one place and set up a packet of info you need later, OR analyze your data and take action on within a few lines.



                Look for repetition and factor it into subroutines.



                Putting a bunch of related (or not) variables into a hash doesn't really do much except add syntax to access or mutate the values.



                Let's analyze your code. It does one of five things with all inputs:



                1. Runs some PSGI application code

                2. Redirects to another URL

                3. Returns HTTP 401 status: Unauthorized.

                4. Returns HTTP 404 status: Not found with two different response bodies.

                Well, 404 with the form data (whatever that is) is your fallback case. If you have a user_id then you redirect, run code if you have it, or 404. And you 401 if you your referrer data looks fishy.



                So your app boils down to:



                sub app 
                my $env = shift;

                return
                get_user_id($env) ? run_app_or_redirect($env)
                : is_request_authorized($env) ? FILE_NOT_FOUND( get_form($env) )
                : UNAUTHORIZED( get_form($env) )
                ;



                Huh, wow, checking auth only for not found? That's probably a bug. For now, let's forge ahead.



                The FILE_NOT_FOUND and other error subs just look like this:



                sub FILE_NOT_FOUND 
                my @body = @_;
                my $default_message = "Not Found, go to : <a href='/'>Home </a> ";

                return ["404", ["Content-Type" => "text/html"], [ @body ? @body : $default_message ]];



                The getters that fetch values from $env are like this:



                sub get_user 
                my $env = shift;
                return $env->'psgix.session'user_id // '';



                Checking request authorization is combines the lookup when you set fromreferer and the spot where you check it to maybe return an error message.



                sub is_request_authorized 
                my $env = shift;
                return '/' eq $env->PATH_INFO;



                The tricky one is, of course, run_app_or_redirect(). I'm not going to work that all out for you. You should be able to do that yourself and probably better than I can since you know the problem domain. Just break the code into sections. First decide which thing you are going to do, and then collect the information needed to do it. You may even wish to make the main sub look like:



                sub app 


                I hope this helps.






                share|improve this answer























                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  First, install perltidy and run it against your code until you get used to looking at well formatted code and type it that way.



                  Second, names are really, really important. Names for functions and variables should be readable (use camel case or snake case to break up long names, but be consistent) and descriptive. Make sure the names are spelled correctly. Don't use names like greater_than_ten. The rule may change and you start caring about URLs with more than 12 or 8 digits. Instead name it for the meaning. Maybe something $url_with_token



                  You have logic and effects all mixed up and spread out. Instead of setting a variable at line 10 and then maybe resetting at line 30 so that you can use it at line 90, (line numbers are hypothetical here), either do all your input analysis in one place and set up a packet of info you need later, OR analyze your data and take action on within a few lines.



                  Look for repetition and factor it into subroutines.



                  Putting a bunch of related (or not) variables into a hash doesn't really do much except add syntax to access or mutate the values.



                  Let's analyze your code. It does one of five things with all inputs:



                  1. Runs some PSGI application code

                  2. Redirects to another URL

                  3. Returns HTTP 401 status: Unauthorized.

                  4. Returns HTTP 404 status: Not found with two different response bodies.

                  Well, 404 with the form data (whatever that is) is your fallback case. If you have a user_id then you redirect, run code if you have it, or 404. And you 401 if you your referrer data looks fishy.



                  So your app boils down to:



                  sub app 
                  my $env = shift;

                  return
                  get_user_id($env) ? run_app_or_redirect($env)
                  : is_request_authorized($env) ? FILE_NOT_FOUND( get_form($env) )
                  : UNAUTHORIZED( get_form($env) )
                  ;



                  Huh, wow, checking auth only for not found? That's probably a bug. For now, let's forge ahead.



                  The FILE_NOT_FOUND and other error subs just look like this:



                  sub FILE_NOT_FOUND 
                  my @body = @_;
                  my $default_message = "Not Found, go to : <a href='/'>Home </a> ";

                  return ["404", ["Content-Type" => "text/html"], [ @body ? @body : $default_message ]];



                  The getters that fetch values from $env are like this:



                  sub get_user 
                  my $env = shift;
                  return $env->'psgix.session'user_id // '';



                  Checking request authorization is combines the lookup when you set fromreferer and the spot where you check it to maybe return an error message.



                  sub is_request_authorized 
                  my $env = shift;
                  return '/' eq $env->PATH_INFO;



                  The tricky one is, of course, run_app_or_redirect(). I'm not going to work that all out for you. You should be able to do that yourself and probably better than I can since you know the problem domain. Just break the code into sections. First decide which thing you are going to do, and then collect the information needed to do it. You may even wish to make the main sub look like:



                  sub app 


                  I hope this helps.






                  share|improve this answer













                  First, install perltidy and run it against your code until you get used to looking at well formatted code and type it that way.



                  Second, names are really, really important. Names for functions and variables should be readable (use camel case or snake case to break up long names, but be consistent) and descriptive. Make sure the names are spelled correctly. Don't use names like greater_than_ten. The rule may change and you start caring about URLs with more than 12 or 8 digits. Instead name it for the meaning. Maybe something $url_with_token



                  You have logic and effects all mixed up and spread out. Instead of setting a variable at line 10 and then maybe resetting at line 30 so that you can use it at line 90, (line numbers are hypothetical here), either do all your input analysis in one place and set up a packet of info you need later, OR analyze your data and take action on within a few lines.



                  Look for repetition and factor it into subroutines.



                  Putting a bunch of related (or not) variables into a hash doesn't really do much except add syntax to access or mutate the values.



                  Let's analyze your code. It does one of five things with all inputs:



                  1. Runs some PSGI application code

                  2. Redirects to another URL

                  3. Returns HTTP 401 status: Unauthorized.

                  4. Returns HTTP 404 status: Not found with two different response bodies.

                  Well, 404 with the form data (whatever that is) is your fallback case. If you have a user_id then you redirect, run code if you have it, or 404. And you 401 if you your referrer data looks fishy.



                  So your app boils down to:



                  sub app 
                  my $env = shift;

                  return
                  get_user_id($env) ? run_app_or_redirect($env)
                  : is_request_authorized($env) ? FILE_NOT_FOUND( get_form($env) )
                  : UNAUTHORIZED( get_form($env) )
                  ;



                  Huh, wow, checking auth only for not found? That's probably a bug. For now, let's forge ahead.



                  The FILE_NOT_FOUND and other error subs just look like this:



                  sub FILE_NOT_FOUND 
                  my @body = @_;
                  my $default_message = "Not Found, go to : <a href='/'>Home </a> ";

                  return ["404", ["Content-Type" => "text/html"], [ @body ? @body : $default_message ]];



                  The getters that fetch values from $env are like this:



                  sub get_user 
                  my $env = shift;
                  return $env->'psgix.session'user_id // '';



                  Checking request authorization is combines the lookup when you set fromreferer and the spot where you check it to maybe return an error message.



                  sub is_request_authorized 
                  my $env = shift;
                  return '/' eq $env->PATH_INFO;



                  The tricky one is, of course, run_app_or_redirect(). I'm not going to work that all out for you. You should be able to do that yourself and probably better than I can since you know the problem domain. Just break the code into sections. First decide which thing you are going to do, and then collect the information needed to do it. You may even wish to make the main sub look like:



                  sub app 


                  I hope this helps.







                  share|improve this answer













                  share|improve this answer



                  share|improve this answer











                  answered Aug 3 at 23:33









                  daotoad

                  30013




                  30013






















                       

                      draft saved


                      draft discarded


























                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f199601%2fassigning-several-variables-from-request-url-using-regexes%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Popular posts from this blog

                      Read files from a directory using Promises

                      Read an image with ADNS2610 optical sensor and Arduino Uno

                      Chat program with C++ and SFML