Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Seekers of Perl Wisdom

( #479=superdoc: print w/replies, xml ) Need Help??

If you have a question on how to do something in Perl, or you need a Perl solution to an actual real-life problem, or you're unsure why something you've tried just isn't working... then this section is the place to ask.

However, you might consider asking in the chatterbox first (if you're a registered user). The response time tends to be quicker, and if it turns out that the problem/solutions are too much for the cb to handle, the kind monks will be sure to direct you here.

Post a new question!

User Questions
[OT:] Is this Curriculum right?
3 direct replies — Read more / Contribute
by karlgoethebier
on Nov 24, 2021 at 09:37

    Dear fellow monks,

    currently Iím coaching a young man who is preparing for his examination as Fachinformatiker.

    This is what we call in German Nachhilfe. As some things went wrong during the education in 3(!) years this step is absolutely necessary.

    For some reasons that I didnít understand yet some guys responsible for the curriculum jumped to the conclusion to bother the kids with linked lists.

    I donít see any reason for the moment to make it so. As far as i can see it for now the boys have more basic problems.

    Thanks for any hint and best regards, Karl

    Update: Thanks to all for the kind and inspiring replies.

    ęThe Crux of the Biscuit is the ApostropheĽ

Unable to connect to Oracle 19c
3 direct replies — Read more / Contribute
by SpaceCowboy
on Nov 24, 2021 at 00:19
    Hello Monks,

    Perl newbie here. I have a windows 10 machine, with Strawberry Perl installed (5.32.1 - Jan 2021 release) that apparently comes preloaded with DBI and DBD::Oracle driver. however, I am unable to connect with my local oracle 19c instance that I have on my machine.

    I researched some questions and they all seem to point to installing a 32-bit oracle client, that is no longer available to download. Please can you help. Here is my code:

    # database connector # load all the libraries use DBI; use warnings; # print("\n\n\tA\n\n"); my @drivers = DBI->available_drivers(); =pod foreach my $driver (@drivers) { print ("$driver \n "); my @dataSources = DBI->data_sources($driver); foreach my $datasource (@dataSources) { print("\t $datasource\n"); } } =cut $dbname = "orcl"; $driver = "oracle"; $host = "localhost"; $username = "meeee"; $password = "000000000000"; $dsn = "dbi:oracle:orcl;host=$host;port=1539"; $dbh = DBI->connect("dbi:oracle:host=localhost;port=1539",$username,$p +assword) or die $DBI::errstr; exit;


    and here is the output I received

    Name "main::driver" used only once: possible typo at .\dbconnect.pl l +ine 21. Name "main::dsn" used only once: possible typo at .\dbconnect.pl line +25. Name "main::dbh" used only once: possible typo at .\dbconnect.pl line +27. Name "main::dbname" used only once: possible typo at .\dbconnect.pl li +ne 20. DBD::oracle initialisation failed: Can't locate object method "driver" + via package "DBD::oracle" at C:/Strawberry/perl/vendor/lib/DBI.pm li +ne 829. Perhaps the capitalisation of DBD 'oracle' isn't right. at .\dbconnect +.pl line 27.


    Solution

    The connection string needs 'Oracle' to be mentioned, along with the datatabse SID in connection string.

    Also, there seems to be legacy documentations that suggests installing Oracle Instant Client, Visual C++ distributable and Windows SDK to get Perl/DBD::Oracle interact with a oracle database in windows operating system.

    I did not do any of these and yet it worked for me with Strawberry Perl 5.32.1 (Jan 2021). So please consider the environment before moving to installing a bunch of dependencies which one may or may not need/be applicable anymore. I already wasted time and effort attempting to locate legacy drivers and SDKs that was never needed.
Faster with my keyword or no ?
4 direct replies — Read more / Contribute
by abdan
on Nov 23, 2021 at 19:39
    Is having my keyword precedes identifier var. speed up the Perl performance compare to otherwise ?
Pattern matching regex problem
2 direct replies — Read more / Contribute
by Anonymous Monk
on Nov 23, 2021 at 03:32
    Hi Monks,
    I wanted your help to fix a couple of pattern matching regex that I have. My script:
    #!/usr/bin/perl use strict; use warnings; my $s='IIIIIIIIIIIIIIIIIIIIIIIIIIOOOOOSSSSS'; if (0 == $s =~ tr/[IOSM]//c) { print "case1\n"; } elsif (0 == $s =~ tr/[IOS]//c) { print "case2\n"; }

    Can you tell me why it prints case1 although my string does not have M inside?
Regex with HTML::Entities
3 direct replies — Read more / Contribute
by Horst.Lohnstein
on Nov 23, 2021 at 01:38

    Hi Monks,

    I have a question concerning Regex with HTML::Entities. I try to replace patterns with a keyword with some HTML-Code: The keword is encapsulated between ✶ (a little star). The keyword itself is of the form: Adjektive (Nominalflexion~84. The whole pattern looks like: {✶Adjektive (Nominalflexion)~87✶}

    use HTML::Entities; # $text is some Text from a mysql database my $sep = decode_entities('✶'); my @v = ($text =~ /\{$sep(.*?)$sep\}/sg); # alle Verweise # @v contains all patterns (which means that they match)

    The matched elements in @v have the form: {✶Adjektive (Nominalflexion)~87✶} Going through all elements in @v, I try to replace the matched elements in the following way:

    $b = "Adjektive (Nominalflexion)~87"; $c = "\{$sep$b$sep\}"; $r = "<div>some Text $b some other text</div>"; $text =~ s/$c/$r/s;

    I tried a lot of variants including quotes (?:...), and what not. Nothing worked! Is there anyone, who can stop my wasting of time with these questions? Thanks in advance! Best regards, Horst

Comparing string characters
3 direct replies — Read more / Contribute
by dnamonk
on Nov 22, 2021 at 11:35
    Hello Monks,

    I am wondering what is the easiest way to compare substrings to know how many mismatches are there. For example:

    String1 String2 #Mismatches

    ABCGE ABCGE 0

    ABCGE FGCGB 3

    ABCGE JHAGT 4

    I was thinking to compare arrays. Or maybe create a hash array and then use index() ?

    Thanks in advance :)
Hash versus chain of elsifs
5 direct replies — Read more / Contribute
by mldvx4
on Nov 22, 2021 at 02:32

    I have a question about what is more efficient for a small lookup function with only a few thousand items. Specifically I have a function in a module and that module has a function which gets passed a string. The function needs to determine if that string is in a set of a few thousand strings or not. How is that done most efficiently, and does the "best" approach vary by scale?

    One way might be to load a hash with the strings as keys, and then see if defined($hash{$string}) or if defined($hash{$string}) has a value set.

    Another would be to have a chain of elsif statements, and have the function cascade through those until either the end is reached or a match has been found.

    Which approach is more appropriate or efficient? Or are the better approaches which can be used?

The debugger not save the commands its in interactive
2 direct replies — Read more / Contribute
by abdan
on Nov 20, 2021 at 18:45
    How come the debugger not save its commands fed in (only save the perl expression/command) after quit and reenter into interactive ?
    How to solve to save everything ?
Why Perl Docs examples do not use strict and warnings often
3 direct replies — Read more / Contribute
by Anonymous Monk
on Nov 20, 2021 at 07:17

    Hi Monks,

    I was browsing through the Perl Data Structures documentation and noticed that though the document suggests using strict, it's not used in any examples.

    How's someone who's new to Perl supposed to know when some internally provided variable is being used vs when a user created variable is being used in the code?

Problem with regex is a bug? or my regex
2 direct replies — Read more / Contribute
by hanspr
on Nov 19, 2021 at 21:48
    Hi , dear monks

    I'm using expect to detect login sequences, and I'm facing this un-explicable behaviour of my regex

    This is the regex
    (([#%:>~\$\] ])(?!\2)){3,4}|([\w\-\.]*)\$ *$|(\w[@\/]\w|sftp).*?[#%>~\ +$\]]|^[#%\$>\:]~] *$

    And the text it fails against is shown below.

    This regex runs correctly in Perl 5.30

    And it fails in Perl 5.34

    It works as expected in testing websites as : https://regex101.com/

    I expected to match this sequence --> : ~#

    But instead is matching --> \s\s#

    as seen in the "Match string message below"

    Match string: ` #'


    I would like to confirm with your wisdom before opening bug request.
    ###################################################################### +######## # This system is a restricted access system. + # # If collected security information reveals possible criminal activity + that # # exceeds privileges, evidence of such activity may be provided to the + rele- # # vant authorities for further action. By continuing past this point, +you # # expressly consent to this security monitoring. + # ###################################################################### +######## hostname: ~# spawn id(5): Does `################################################### +###########################\r\n# This system is a restricted access s +ystem. #\r\n# If collected security i +nformation reveals possible criminal activity that #\r\n# exceeds pr +ivileges, evidence of such activity may be provided to the rele- #\r\ +n# vant authorities for further action. By continuing past this point +, you #\r\n# expressly consent to this security monitoring. + #\r\n########################################## +####################################\r\n\r\nhostname: ~# ' match: pattern #2: -eof `'? No. pattern #3: -re `\\[__PAC__SUDO__PROMPT__\\]'? No. pattern #4: -re `^.+ontinue connecting \\(([^/]+)\\/([^/]+)(?:[^)]+) +?\\)\\?\\s*$'? No. pattern #5: -re `.*(any key to continue|tecla para continuar).*'? No +. pattern #6: -re `.*ffending .*key in (.+?)\\:(\\d+).*'? No. pattern #7: -re `([lL]ogin|[uU]suario|([uU]ser-?)*[nN]ame.*|[uU]ser) +\\s*:\\s*$'? No. pattern #8: -re `([pP]ass|[pP]ass[wW]or[dt](\\s+for\\s+|\\w+@[\\w\\- +\\.]+)*|[cC]ontrase.a|Enter passphrase for key \'.+\')\\s*:\\s*$'? No +. pattern #9: -re `(([#%:>~\\$\\] ])(?!\\2)){3,4}|([\\w\\-\\.]*)\\$ *$ +|\\w[@\\/]\\w.*?[#%>~\\$\\]]|^[#%\\$>\\:]~] *$'? YES!! Before match string: `############################################ +##################################\r\n# This system is a restricted a +ccess system. ' Match string: ` #' After match string: `\r\n# If collected security information revea +ls possible criminal activity that #\r\n# exceeds privileges, eviden +ce of such activity may be provided to the rele- #\r\n# vant authorit +ies for further action. By continuing past this point, you #\r\n# +expressly consent to this security monitoring. + #\r\n########################################################## +####################\r\n\r\n\r\nhostname: ~# ' Matchlist: (`#', `#', `') Calling hook CODE(0x55f2fb33fe20)...

Add your question
Title:
Your question:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":


  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2021-11-29 09:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?