[dancer-users] get session info without route

David Precious davidp at preshweb.co.uk
Tue Sep 10 16:04:23 BST 2013


On Tue, 10 Sep 2013 16:42:37 +0200
Hugues Max <huguesmax at gmail.com> wrote:

> if I understand well, vars and  session can't be use outside of
> route,OK but  all rest of code can works correctly ?

Yeah - but code outside of route handlers / hooks will run at initial
startup.  That can be useful though, to set stuff up.  In the example
you gave, the global var you set can then be used within routes etc.

A few comments on your code:

> foreach my $fichier(@fichier) {
>          if ($fichier=~/\.xls$/i || $fichier=~/\.xlsx/i){
>                  my ($filename, $directory ) = fileparse($fichier);
>                  $fichierXls=$filename;
>          }
> }

You can match .xls/.xlsx in one regex with e.g.:

if ($fichier =~ /\.xlsx?$/i) {
    ...
}

You also missed anchoring to end of string in the second regex, so a
filename like fooxlsxfoo.jpg would match your check.

Also, you're going to look at every file you found and set $fichierXls
each time you find a spreadsheet file, so you'll end up with just the
filename of the last one found in $fichierXls.  It's not clear if
that's the desired behaviour or not.

Cheers

Dave P


-- 
David Precious ("bigpresh") <davidp at preshweb.co.uk>
http://www.preshweb.co.uk/     www.preshweb.co.uk/twitter
www.preshweb.co.uk/linkedin    www.preshweb.co.uk/facebook
www.preshweb.co.uk/cpan        www.preshweb.co.uk/github




More information about the dancer-users mailing list