Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: In my perl script one of the variable it is giving an extra dot.

by Discipulus (Canon)
on May 25, 2022 at 08:19 UTC ( [id://11144180]=note: print w/replies, xml ) Need Help??


in reply to In my perl script one of the variable it is giving an extra dot.

Hello Anonymous Monk,

if you want to use the regex be sure to use an anchor to just remove a dot in the beginning of the string:  /^\./ being the dot a special regex char you need to escape it.

For a more robust solution use File::Spec file_name_is_absolute and rel2abs

# something like.. $path = File::Spec->rel2abs( $path ) unless File::Spec->file_name_is_a +bsolute( $path )

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^2: In my perl script one of the variable it is giving an extra dot.
by hippo (Bishop) on May 25, 2022 at 09:23 UTC

    Note that the rel2abs approach will only give the same result if / is the CWD. Otherwise it's a different result:

    #!/usr/bin/env perl use strict; use warnings; use File::Spec; chdir '/tmp'; my $path = './root/git/common/crt_del/cert/DEFAULT.pem'; $path = File::Spec->rel2abs ($path) unless File::Spec->file_name_is_absolute ($path); print "$path\n";

    🦛

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11144180]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-03-29 16:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found