http://qs1969.pair.com?node_id=479

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
10 x 10 table of values
2 direct replies — Read more / Contribute
by dnamonk
on Nov 28, 2021 at 22:47

    Dear Monks,

    I want to create a 10 x 10 table of values. Each entry in the table row of column value is the count of difference in the string characters. Below is an example Table to give an idea about the problem. In this example, even 1 or 2 are allowed but in my case, I want to allow only >= 3 mismatches for string size 6. That is where I am struggling actually as you can see from my program below. For example:

    DOG COT BAL MAN DOG 0 2 3 3 COT 2 0 3 3 BAL 3 3 0 2 MAN 3 3 2 0

    I was thinking to create a random string generator and then count the occurrence of characters and checking the differences in each word. I want to keep atleast 3 differences in my case for randomly generated strings.

    Here is my code so far:

    #!/bin/bash/perl @tests; for($i=0; $i-4; $i++){ my @char = ('M','A','N','O'); my $len = 6; my $string1; my $string2; while($len--){ $string1 .= $char[rand @char]; $string2 .= $char[rand @ +char];}; print "$string1\t$string2\n"; $string = $string1.' '.$string2; push(@tests, $string); } print "Array string"; print "\n"; foreach $GGG (@tests){ print $GGG; print "\n"; } #print $string; $stringA = 'ABCGE'; $stringB = 'ABCGE'; $mystring = $stringA.' '.$stringB; my @tests = ( [split / /, $mystring;], [qw{ABCGE FGCGB}], [qw{ABCGE JHAGT}], ); foreach $strings (@tests) { my $diff = 0; for my $i (0 .. length($strings->[0]) - 1) { my @chars = map substr($strings->[$_], $i, 1), 0, 1; ++$diff if $chars[0] ne $chars[1]; } print "@$strings $diff\n"; }
Recalling a function iteratively
3 direct replies — Read more / Contribute
by dnamonk
on Nov 28, 2021 at 21:18
    Dear Monks, I have a general logic question. I need help in logic and not code. I have a question about recalling my function within a loop. Below is my code:
    List_new = myfunction() for items in List_new: if(my condition is TRUE): Execute some commands if(my condition is FALSE): recall myfunction()
    My problem is that I am loading "List_new" using myfunction(). How can I change "List_new" iteratively when my condition is False. I want to reload the function especially when the condition is FALSE. This means I keep calling the function until it is false and then execute the final output from myfunction(). Thank you in advance for your help.
A Win32 new Perl build dilemma
3 direct replies — Read more / Contribute
by mikegold10
on Nov 28, 2021 at 20:46

    I just built a version of the latest version of Perl, v5.35.6, from source and am having an odd issue with the output of the ASCII Escape character when it is printed. When I run a script at the Windows 10 command prompt, Perl, instead of dumping the Escape character as a literal character into the console when instructed to do so, prints a left pointing arrow (probably the printable glyph representation of the Escape character). Before I present a code example, I should add for completeness sake that I am in the default Windows code page of 437. (Verified via chcp, which reports: Active code page: 437 . Playing with the code page (e.g., changing it to 65001 or 1252) doesn't help, other than to make the left-pointing-arrow as shown below into a non-printable "box" character representation, probably because the glyph representation of Escape being printed by Perl as a left pointing arrow is invalid for those two code pages or whatever is coming out is missing from the characters in the Consolas font I am using for my Command Prompt). Here is an example: (Clarification: a pair of double-quotes is used to cause double-quotes to get escaped for proper cmd.exe interpretation):

    perl.exe -e "print ""this \x1B[1;31mred\x1B[0m text\n"" "
    Output (Incorrect - Perl is changing the chr(27) that precedes each left bracket i.e., the Escape ASCII character, into a left arrow):
    this ←[1;31mred←[0m text
    What I am trying to do is to use an ANSI Escape Code above to change the color of the text to red for the word "red" (i.e., <Esc>[1;31m ==> Set foreground color to 31 Red and <Esc>[0m ==> Reset all modes/styles). For some bizarre reason, Perl is causing a character U+2190, best I can tell, which is the Unicode representation of a left-arrow (a glyph that is sometimes used to represent the <Esc> character as a printable character) to be output instead of the proper Escape ASCII character I am expecting. There is nothing wrong with the code, mind you, because if I do the following:
    perl.exe -e "print ""this \x1B[1;31mred\x1B[0m text\n"" " | cat
    Output (correct):
    this red text
    So, it seems like Perl is treating a redirection of STDOUT differently and actually sending a proper escape character. I also tried the following (redirecting output to a file and outputting said file, instead of piping to cat) to see what happens:
    perl.exe -e "print ""this \x1B[1;31mred\x1B[0m text\n"" " >tmp.txt & t +ype tmp.txt
    Output (correct):
    this red text
    Just to make absolutely certain that the issue is not with the code or some misbehavior of the windows command prompt (i.e., c:\windows\system32\cmd.exe), I ran the code through a different Perl interpreter, the one that comes with Cygwin, to see how it would behave in this case:
    c:\cygwin64\bin\perl5.32.1.exe -e "print ""this \x1B[1;31mred\x1B[0m t +ext\n"" "
    Output (correct):
    this red text
    Perhaps to no surprise, the Cywin Perl interpreter did the right thing, even though its output was not in any way redirected. Here is what we can rule out, right off the bat:
    • It is not a Perl 5.35.x issue, because I have an old 5.34 build that behaves in the same way (built with the same build settings/defines).
    • As demonstrated via type/cat/Cygwin Perl, it is not a Windows Command Prompt (i.e., cmd.exe) or active code page issue, either.
    I am not sure what the true cause is, but I believe that the problem may somehow stem from my build config. So let me present it next by using perl -V. I used Visual C++ 2022 as my compiler, for this build and used Visual C++ 2019 for the Perl 5.34 build that behaves in the same way with regard to the Escape character handling:
    C:\>perl.exe -V Summary of my perl5 (revision 5 version 35 subversion 6) configuration +: Platform: osname=MSWin32 osvers=10.0.19043.1348 archname=MSWin32-x64-multi-thread-64int uname='' config_args='undef' hint=recommended useposix=true d_sigaction=undef useithreads=define usemultiplicity=define use64bitint=define use64bitall=undef uselongdouble=undef usemymalloc=n default_inc_excludes_dot=define Compiler: cc='cl' ccflags ='-nologo -GF -W3 -MD -DWIN32 -D_CONSOLE -DNO_STRICT -DNDE +BUG -DWIN64 -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -D +_WINSOCK_DEPRECATED_NO_WARNINGS -DPERL_TEXTMODE_SCRIPTS -DMULTIPLICI +TY -DPERL_IMPLICIT_SYS -DWIN32_NO_REGISTRY' optimize='-O1 -Ob2 -Oi -Oy -GL -Gm- -GS- -Gy -sdl- -Zc:inline -Zi +-fp:precise -arch:AVX512 -fp:precise' cppflags='-DWIN32' ccversion='19.31.30818' gccversion='' gccosandvers='' intsize=4 longsize=4 ptrsize=8 doublesize=8 byteorder=12345678 doublekind=3 d_longlong=undef longlongsize=8 d_longdbl=define longdblsize=8 longdblkind=0 ivtype='__int64' ivsize=8 nvtype='double' nvsize=8 Off_t='__int64' lseeksize=8 alignbytes=8 prototype=define Linker and Libraries: ld='link' ldflags ='-nologo -nodefaultlib -debug -opt:ref,icf -ltcg -libpat +h:"c:\perl\5.35.6\lib\CORE" -machine:AMD64 -subsystem:console,"6.00" +' libpth="c:\Program Files\Microsoft Visual Studio\2022\Preview\VC\T +ools\MSVC\14.31.30818\\lib\x64" libs=oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib +comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi3 +2.lib uuid.lib ws2_32.lib mpr.lib winmm.lib version.lib odbc32.lib o +dbccp32.lib comctl32.lib msvcrt.lib vcruntime.lib ucrt.lib perllibs=oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.l +ib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib net +api32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib version.lib odbc32.l +ib odbccp32.lib comctl32.lib msvcrt.lib vcruntime.lib ucrt.lib libc=ucrt.lib so=dll useshrplib=true libperl=perl535.lib gnulibc_version='' Dynamic Linking: dlsrc=dl_win32.xs dlext=dll d_dlsymun=undef ccdlflags=' ' cccdlflags=' ' lddlflags='-dll -nologo -nodefaultlib -debug -opt:ref,icf -ltcg - +libpath:"c:\perl\5.35.6\lib\CORE" -machine:AMD64 -subsystem:console, +"6.00"' Characteristics of this binary (from libperl): Compile-time options: HAS_TIMES HAVE_INTERP_INTERN MULTIPLICITY PERLIO_LAYERS PERL_COPY_ON_WRITE PERL_DONT_CREATE_GVSV PERL_IMPLICIT_SYS PERL_MALLOC_WRAP PERL_OP_PARENT PERL_PRESERVE_IVUV USE_64_BIT_INT USE_ITHREADS USE_LARGE_FILES USE_LOCALE USE_LOCALE_COLLATE USE_LOCALE_CTYPE USE_LOCALE_NUMERIC USE_LOCALE_TIME USE_NO_REGISTRY USE_PERLIO USE_PERL_ATOF USE_THREAD_SAFE_LOCALE Built under MSWin32 Compiled at Nov 27 2021 18:54:37 @INC: c:/perl/5.35.6/lib
    Just to compare and contrast, here is what the Perl from Cygwin has as its configuration:
    c:\>perl5.32.1.exe -V Summary of my perl5 (revision 5 version 32 subversion 1) configuration +: Platform: osname=cygwin osvers=3.2.0(0.34053) archname=x86_64-cygwin-threads-multi uname='cygwin_nt-10.0 cygwinpro 3.2.0(0.34053) 2021-03-29 08:42 x8 +6_64 cygwin ' config_args='-des -Dprefix=/usr -Dmksymlinks -Darchname=x86_64-cyg +win-threads -Dlibperl=cygperl5_32.dll -Dcc=gcc -Dld=g++ -Accflags=-gg +db -O2 -pipe -Wall -Werror=format-security -D_FORTIFY_SOURCE=2 -fstac +k-protector-strong --param=ssp-buffer-size=4 -fdebug-prefix-map=/mnt/ +share/cygpkgs/perl/perl.x86_64/build=/usr/src/debug/perl-5.32.1-2 -fd +ebug-prefix-map=/mnt/share/cygpkgs/perl/perl.x86_64/src/perl-5.32.1=/ +usr/src/debug/perl-5.32.1-2 -fwrapv' hint=recommended useposix=true d_sigaction=define useithreads=define usemultiplicity=define use64bitint=define use64bitall=define uselongdouble=undef usemymalloc=n default_inc_excludes_dot=define bincompat5005=undef Compiler: cc='gcc' ccflags ='-DPERL_USE_SAFE_PUTENV -U__STRICT_ANSI__ -D_GNU_SOURCE - +ggdb -O2 -pipe -Wall -Werror=format-security -D_FORTIFY_SOURCE=2 -fst +ack-protector-strong --param=ssp-buffer-size=4 -fdebug-prefix-map=/mn +t/share/cygpkgs/perl/perl.x86_64/build=/usr/src/debug/perl-5.32.1-2 - +fdebug-prefix-map=/mnt/share/cygpkgs/perl/perl.x86_64/src/perl-5.32.1 +=/usr/src/debug/perl-5.32.1-2 -fwrapv -fno-strict-aliasing' optimize='-O3' cppflags='-DPERL_USE_SAFE_PUTENV -U__STRICT_ANSI__ -D_GNU_SOURCE - +ggdb -O2 -pipe -Wall -Werror=format-security -D_FORTIFY_SOURCE=2 -fst +ack-protector-strong --param=ssp-buffer-size=4 -fdebug-prefix-map=/mn +t/share/cygpkgs/perl/perl.x86_64/build=/usr/src/debug/perl-5.32.1-2 - +fdebug-prefix-map=/mnt/share/cygpkgs/perl/perl.x86_64/src/perl-5.32.1 +=/usr/src/debug/perl-5.32.1-2 -fwrapv -fno-strict-aliasing' ccversion='' gccversion='10.2.0' gccosandvers='' intsize=4 longsize=8 ptrsize=8 doublesize=8 byteorder=12345678 doublekind=3 d_longlong=define longlongsize=8 d_longdbl=define longdblsize=16 longdblkind=3 ivtype='long' ivsize=8 nvtype='double' nvsize=8 Off_t='off_t' lseeksize=8 alignbytes=8 prototype=define Linker and Libraries: ld='g++' ldflags =' -Wl,--enable-auto-import -Wl,--export-all-symbols -Wl,- +-enable-auto-image-base -fstack-protector-strong' libpth=/usr/lib libs=-lpthread -lnsl -lgdbm -ldb -ldl -lcrypt -lgdbm_compat perllibs=-lpthread -lnsl -ldl -lcrypt libc=/usr/lib/libcygwin.a so=dll useshrplib=true libperl=cygperl5_32.dll gnulibc_version='' Dynamic Linking: dlsrc=dl_dlopen.xs dlext=dll d_dlsymun=undef ccdlflags=' ' cccdlflags=' ' lddlflags=' --shared -Wl,--enable-auto-import -Wl,--export-all-sy +mbols -Wl,--enable-auto-image-base -fstack-protector-strong' Characteristics of this binary (from libperl): Compile-time options: HAS_TIMES MULTIPLICITY PERLIO_LAYERS PERL_COPY_ON_WRITE PERL_DONT_CREATE_GVSV PERL_IMPLICIT_CONTEXT PERL_OP_PARENT PERL_PRESERVE_IVUV PERL_USE_SAFE_PUTENV USE_64_BIT_ALL USE_64_BIT_INT USE_ITHREADS USE_LARGE_FILES USE_LOCALE USE_LOCALE_COLLATE USE_LOCALE_CTYPE USE_LOCALE_NUMERIC USE_LOCALE_TIME USE_PERLIO USE_PERL_ATOF USE_REENTRANT_API USE_THREAD_SAFE_LOCALE Locally applied patches: Cygwin: README Cygwin: use auto-image-base instead of fixed DLL base address Cygwin: modify hints Cygwin: Configure correct libsearch Cygwin: Configure correct libpth Cygwin: Encode fix for CVE-2021-36770 Cygwin: Win32 correct UTF8 handling Built under cygwin Compiled at Aug 14 2021 09:07:12 %ENV: CYGWIN="glob:ignorecase winsymlinks:native pipe_byte" @INC: /usr/local/lib/perl5/site_perl/5.32/x86_64-cygwin-threads /usr/local/share/perl5/site_perl/5.32 /usr/lib/perl5/vendor_perl/5.32/x86_64-cygwin-threads /usr/share/perl5/vendor_perl/5.32 /usr/lib/perl5/5.32/x86_64-cygwin-threads /usr/share/perl5/5.32
File input-output handle defined or no determination
3 direct replies — Read more / Contribute
by abdan
on Nov 26, 2021 at 20:29
    How can we check Perl input-output handle e.g. open R,"$file" is defined or existing, as it's needed or useful to be tested later ?
running system commands, and getting return codes/status
3 direct replies — Read more / Contribute
by Anonymous Monk
on Nov 26, 2021 at 19:59

    Below is my code. It runs a backup program from a pTk GUI. My problem is at the 'system($cmd)' statement. The command gets executed before the message gets displayed in the text widget.

    I want a message that tells * is being done, then when the process is done a message that says * is done along with relevant error codes.

    Is there a better way to do this? And why are the messages displayed at the wrong time?

    my @cmd = ""; push (@cmd , $prog_args , $fullf +ile2 , "/" ); my $cmd2 = join " " , @cmd +; $text -> delete ('1.0' , 'end' ); $text -> insert ('end' , "\n" ); $text -> insert ('end' , "THIS +OPERATION SHOULD TAKE 5 min. to 15 min. \n ", 'highlite' ); my $exit_status = system( +$cmd2 ); print "\$exit_statu +s at L1447 =: $exit_status\n"; if ( 0 == $exit_sta +tus ) { $text -> insert ('end' , "\n\n" ); $text -> insert ('end' , "DONE! \n", 'h +ighlite' ); }
TK/HList and focus
1 direct reply — Read more / Contribute
by andyok
on Nov 26, 2021 at 11:18

    I have trouble with focus and a HList.

    I wanted my HList to have clickable headers:

    • The intention being that the user could click on a header to indicate that the list should be sorted by that column
    • I don't think HList natively supports clickable headers
    • So I thought I'd use the -itemtype=>"window" feature

    The code snippet attached at the end is the simplest test-case I could come up with.

    You might think "Why would anyone have a GUI like this" ... but this code is purely to demonstrate the problem.

    With the script running, and with the window made nice'n'wide, to demonstrate the problem:

    • Start with your mouse hovering over Button1 and then move the mouse left and then vertically down through the ABC header and down into the HList ... the HList focus highlight rectangle appears (there is no need to click a HList entry).
    • Return to Button1 and then move the mouse left and then vertically down through the DEF label and down into the HList ... the HList focus highlight rectangle no longer appears
    • Return to Button1 and then move the mouse left and then vertically down through the GHI button and down into the HList ... again, the HList focus highlight rectangle no longer appears.

    Isn't it curious that the highlight rectangle doesn't appear when in the HList entries when the mouse transitions through the Label and button widgets?

    You may well be asking, "why is this important" ... well because, in my full script (not in this example) I have a keyboard binding for the Escape-key to unselect all HList entries ... but this only works when the HList has the keyboard focus ... and the keyboard focus seems to be very dependent on the route the mouse took to get to the HList.

    Questions:

    • Can anyone else reproduce this?
    • As a side issue, why is the label DEF not centred (centered)?
    • Any ideas as to how to get the HList focus when traversing through widgets as headers?
    • Is there a better way to get clickable headers?

    Thank you very much for your time.

    Andrew

    #!/usr/bin/perl use Tk; use Tk::HList; my $mw = MainWindow->new(); $b1 = $mw->Button(-text=>"Button1")->pack(); $b2 = $mw->Button(-text=>"Button2")->pack(); $hlist = $mw->HList( -selectmode => 'single', -columns=>3, -background +=>"Wheat", -header=>1)->pack(-fill=>'both',-expand=>1); $hlist -> focusFollowsMouse(); $hlist -> headerCreate(0, -text=>"ABC"); $label = $hlist->Label(-text=>"DEF", -pady=>1); $hlist -> headerCreate(1, -itemtype=>"window", -window=>$label); $button = $hlist->Button(-text=>"GHI"); $hlist -> headerCreate(2, -itemtype=>"window", -window=>$button); for (1..9) { $hlist->add($_); $hlist->itemCreate($_, 0, -text=>"$_"x5); $hlist->itemCreate($_, 1, -text=>"$_"x10); } MainLoop;
Perl DBI, Oracle truncating 30th character from the column name.
1 direct reply — Read more / Contribute
by Anonymous Monk
on Nov 26, 2021 at 06:14

    Hi Monks,

    While fetching data from Oracle db using Perl DBI, since column name is lengthy enough, oracle is truncating the 30th character from the column name, because of it's column length restriction it seems.

    Is there anything we can do using perl DBI to avoid this column name truncation from the result set.

    Thank you

RK4 for a vectorial function
4 direct replies — Read more / Contribute
by Lucero
on Nov 25, 2021 at 21:38
    Hello. Im trying to calculate the transition probability for a constant pertubation. What I have to do is apply the RK4 method to a vectorial function
    :fn(cm, t) =sum over m((-i/h)*<n|V|m>exp(-i(Em -En)t/h))Cm)
    The values of |cm|^2 must oscillate around 1 and 0 but I run the code the values I get are bigger and dont have the oscillatory behavior.
    use warnings; use strict; use PDL; use PDL::Complex; my $eprim=0.001; my $X =pdl [ [ 0, -sqrt(1),0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +], [sqrt(1),0, sqrt(2),0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +,0,0], [0, sqrt(2),0,sqrt(3),0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +,0,0], [0,0,sqrt(3),0,sqrt(4),0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0], [0,0,0,sqrt(4),0,sqrt(5),0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0], [0,0,0,0,sqrt(5),0,sqrt(6),0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0], [0,0,0,0,0,sqrt(6),0,sqrt(7),0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0], [0,0,0,0,0,0,sqrt(7),0,sqrt(8),0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0], [0,0,0,0,0,0,0,sqrt(8),0,sqrt(9),0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0], [0,0,0,0,0,0,0,0,sqrt(9),0,sqrt(10),0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +,0,0], [0,0,0,0,0,0,0,0,0,sqrt(10),0,sqrt(11),0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0], [0,0,0,0,0,0,0,0,0,0,sqrt(11),0,sqrt(12),0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0], [0,0,0,0,0,0,0,0,0,0,0,sqrt(12),0,sqrt(13),0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,sqrt(13),0,sqrt(14),0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,sqrt(14),0,sqrt(15),0,0,0,0,0,0,0,0,0,0, +0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,sqrt(15),0,sqrt(16),0,0,0,0,0,0,0,0,0, +0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,sqrt(16),0,sqrt(17),0,0,0,0,0,0,0,0, +0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,sqrt(17),0,sqrt(18),0,0,0,0,0,0,0, +0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,sqrt(18),0,sqrt(19),0,0,0,0,0,0, +0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,sqrt(19),0,sqrt(20),0,0,0,0,0, +0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,sqrt(20),0,sqrt(21),0,0,0,0, +0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,sqrt(21),0,sqrt(22),0,0,0, +0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,sqrt(22),0,sqrt(23),0,0, +0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,sqrt(23),0,sqrt(24),0, +0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,sqrt(24),0,sqrt(25), +0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,sqrt(25),0,sqrt(26 +),0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,sqrt(26),0,sqrt( +27),0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,sqrt(27),0,sqr +t(27)], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,sqrt(28),0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,sqrt(28)] ]; my $vec= pdl [ [ -0.4037003675364034,-0.0000000000000169,-0.8381213708160592,-0.0000 +000000000158,-0.3190879932741590,0.0000000000000003,0.169355258154224 +8,0.0000000000000032,0.0251289794138005,-0.0000000000000012,-0.053630 +0581595280,-0.0000000000000003,0.0217496956429717,0.0000000000000005, +0.0021651419544516,-0.0000000000000002,-0.0080249333137898,0.00000000 +00000000,0.0051470455076793,0.0000000000000001,-0.0013650508619321,-0 +.0000000000000001,-0.0006214095672646,0.0000000000000000,0.0010251417 +156844,-0.0000000000000000,-0.0007344546098787,-0.0000000000000000,0. +0003358368423501,0.0000000000000000 ], [ -0.0000000000000095,0.7226441842331763,-0.0000000000000196,0.674369 +4628487641,-0.0000000000000074,-0.0126709869133627,0.0000000000000039 +,-0.1390097337149938,0.0000000000000004,0.0532637295249766,-0.0000000 +000000012,0.0108058217041577,0.0000000000000004,-0.0211856923535512,- +0.0000000000000004,0.0104565487807121,0.0000000000000001,-0.000802132 +1669403,-0.0000000000000003,-0.0027244498764788,0.0000000000000004,0. +0023881197288006,-0.0000000000000006,-0.0010161248442056,0.0000000000 +000009,0.0000173027596815,-0.0000000000000008,0.0003416491521171,0.00 +00000000000006,-0.0002612727358195 ], [ -0.7265845261792991,0.0000000000000004,0.0822771629823105,-0.000000 +0000000005,0.6492960190820365,-0.0000000000000003,-0.0423366396915736 +,0.0000000000000002,-0.1758256491790640,0.0000000000000000,0.09794090 +67513942,-0.0000000000000001,-0.0028801939655116,0.0000000000000000,- +0.0292811602848338,0.0000000000000000,0.0218748117671870,-0.000000000 +0000000,-0.0068869463649583,0.0000000000000000,-0.0019130055021425,-0 +.0000000000000000,0.0039694711332578,0.0000000000000000,-0.0028100428 +723103,-0.0000000000000000,0.0012454407121507,-0.0000000000000000,-0. +0003466238255135,0.0000000000000000 ], [ 0.0000000000000006,0.6010733799547240,-0.0000000000000001,-0.593736 +8797404066,-0.0000000000000004,-0.4447140685185609,0.0000000000000001 +,0.2753043611569276,0.0000000000000001,0.0177297849332504,-0.00000000 +00000001,-0.0947825000175309,0.0000000000000001,0.0539543068519576,-0 +.0000000000000003,-0.0064734473245184,0.0000000000000001,-0.013191845 +5031492,0.0000000000000004,0.0125678040256591,0.0000000000000000,-0.0 +057077804477274,-0.0000000000000002,0.0003357404158152,0.000000000000 +0007,0.0018880365733295,-0.0000000000000005,-0.0019443492967520,0.000 +0000000000001,0.0010789173843832 ], [ 0.5430269760782945,-0.0000000000000001,-0.4474156032695855,-0.00000 +00000000000,0.5801000179013242,0.0000000000000002,0.2404758383494775, +-0.0000000000000002,-0.3088519136114667,0.0000000000000001,0.08237883 +44472166,0.0000000000000000,0.0541280464126355,-0.0000000000000001,-0 +.0660462396199596,0.0000000000000000,0.0305535579726857,-0.0000000000 +000000,-0.0009344967473301,-0.0000000000000000,-0.0099964129968316,0. +0000000000000000,0.0087666379065681,-0.0000000000000000,-0.0040952318 +231305,0.0000000000000000,0.0007413411176992,-0.0000000000000000,0.00 +03124230406161,0.0000000000000000 ], [ 0.0000000000000000,0.3321617007160794,-0.0000000000000001,-0.331456 +4696269089,-0.0000000000000002,0.7974495377138241,-0.0000000000000004 +,-0.0513734221888449,0.0000000000000001,-0.3011617902587023,0.0000000 +000000004,0.2082370289532634,-0.0000000000000003,-0.0347605467840875, +-0.0000000000000001,-0.0497057528447874,0.0000000000000006,0.05212963 +36393288,-0.0000000000000008,-0.0250539045206587,0.0000000000000008,0 +.0023068831550118,-0.0000000000000003,0.0074112442261458,0.0000000000 +000001,-0.0079651410760186,0.0000000000000001,0.0051288837146889,-0.0 +000000000000001,-0.0022324847785247 ], [ 0.1172897082030818,-0.0000000000000002,-0.2964728523725000,0.000000 +0000000003,0.1841483714928239,-0.0000000000000005,-0.8047717594409407 +,0.0000000000000009,0.3242847252115117,-0.0000000000000004,0.16364977 +62965390,0.0000000000000000,-0.2529941067981705,0.0000000000000002,0. +1294310921497701,-0.0000000000000002,-0.0062237278459524,0.0000000000 +000001,-0.0444860334138650,0.0000000000000000,0.0406263992613470,-0.0 +000000000000001,-0.0185369919706947,0.0000000000000001,0.000753458698 +2924,-0.0000000000000000,0.0063516252770288,0.0000000000000000,-0.005 +0724227338856,-0.0000000000000000 ], [ -0.0000000000000000,-0.0746816751641777,0.0000000000000003,0.279960 +3944858002,0.0000000000000004,-0.0369884510514530,0.0000000000000016, +0.7185111750625419,0.0000000000000002,-0.5499552865074182,-0.00000000 +00000006,0.0532991069401313,-0.0000000000000002,0.2088524831915762,0. +0000000000000011,-0.1984245945881420,-0.0000000000000011,0.0856956117 +134249,0.0000000000000004,0.0038508424287722,0.0000000000000007,-0.03 +73833868060850,-0.0000000000000012,0.0329127019021361,0.0000000000000 +010,-0.0166509762582109,-0.0000000000000004,0.0042911848981398,-0.000 +0000000000001,0.0002821243295013 ], [ -0.0214780579913734,-0.0000000000000003,0.0372177058109391,0.000000 +0000000003,-0.2944751450270211,-0.0000000000000008,-0.075683024140412 +2,0.0000000000000008,-0.5412748833836341,-0.0000000000000006,0.668676 +2866715919,0.0000000000000003,-0.2932317876571968,0.0000000000000000, +-0.0735660926692254,-0.0000000000000002,0.2050075536886243,0.00000000 +00000001,-0.1583105998876948,-0.0000000000000000,0.0602462844067277,- +0.0000000000000001,0.0115818910911991,0.0000000000000001,-0.039716023 +0068139,-0.0000000000000001,0.0369608788819537,0.0000000000000001,-0. +0202264690881708,-0.0000000000000000 ], [ -0.0000000000000000,0.0238139307663168,0.0000000000000000,0.0126527 +912037899,-0.0000000000000002,0.3264304157504123,-0.0000000000000002, +0.1354442358079246,-0.0000000000000006,0.3188188145305269,0.000000000 +0000004,-0.6646875721923707,-0.0000000000000002,0.4961929745611114,0. +0000000000000003,-0.1255681225264503,-0.0000000000000002,-0.127000931 +5120212,0.0000000000000003,0.1845765986762271,-0.0000000000000001,-0. +1230738673852459,-0.0000000000000004,0.0376175711869895,0.00000000000 +00006,0.0187532845837444,-0.0000000000000005,-0.0354892349606020,0.00 +00000000000004,0.0238711615056090 ], [ 0.0017318840561273,-0.0000000000000002,-0.0324109249717848,0.000000 +0000000007,-0.0699841577530595,-0.0000000000000002,-0.349302010000345 +1,0.0000000000000011,-0.1121863328196896,-0.0000000000000014,-0.10921 +03091430736,-0.0000000000000000,0.5420611831710406,0.0000000000000013 +,-0.6097584088048894,-0.0000000000000015,0.3508901747526678,0.0000000 +000000009,-0.0471175681506413,-0.0000000000000002,-0.1258773221542367 +,-0.0000000000000002,0.1564524321190749,0.0000000000000002,-0.1120328 +335999530,-0.0000000000000002,0.0570522771318334,0.0000000000000001,- +0.0203908274536104,-0.0000000000000001 ], [ 0.0000000000000000,-0.0016213341083221,0.0000000000000001,-0.051098 +7268286506,0.0000000000000003,-0.1334540474130648,0.0000000000000009, +-0.3479817094912636,0.0000000000000007,-0.0311921491179282,0.00000000 +00000001,0.0444673033625089,-0.0000000000000014,0.3398228370041564,0. +0000000000000012,-0.5916539149462523,-0.0000000000000005,0.5108305696 +513560,-0.0000000000000002,-0.2420842730477737,-0.0000000000000003,-0 +.0103981442743016,0.0000000000000013,0.1459764073717070,-0.0000000000 +000019,-0.1690313714662625,0.0000000000000019,0.1276772440329932,-0.0 +000000000000014,-0.0644813878617362 ], [ 0.0011147979892237,-0.0000000000000003,0.0124527283486975,0.0000000 +000000002,0.0947114844587487,-0.0000000000000008,0.2372976408624008,0 +.0000000000000005,0.3557847566629774,0.0000000000000003,-0.0635298085 +436199,-0.0000000000000005,-0.1713173200400193,0.0000000000000002,-0. +0972899291799430,0.0000000000000004,0.4717862901085890,-0.00000000000 +00011,-0.5720800153535275,0.0000000000000016,0.3811052943887194,-0.00 +00000000000018,-0.0912455512043619,0.0000000000000014,-0.119297875587 +9619,-0.0000000000000009,0.1817055145006404,0.0000000000000005,-0.120 +2320521959933,-0.0000000000000002 ], [ -0.0000000000000000,-0.0034343034398039,-0.0000000000000001,-0.0299 +555389414543,-0.0000000000000004,-0.1423655878081122,-0.0000000000000 +012,-0.2861228319386651,-0.0000000000000016,-0.2698629683232922,-0.00 +00000000000006,0.1808943245053649,0.0000000000000014,0.13910518243619 +62,0.0000000000000000,-0.0647414559720777,-0.0000000000000010,-0.2908 +420542400688,0.0000000000000007,0.5446044409698884,0.0000000000000011 +,-0.5243579846618940,-0.0000000000000024,0.3154050447298352,0.0000000 +000000033,-0.0894563929271685,-0.0000000000000028,-0.0389334639461899 +,0.0000000000000014,0.0522795627061793 ], [ -0.0002173011090244,-0.0000000000000015,-0.0060764847307131,-0.0000 +000000000005,-0.0347032140814115,0.0000000000000003,-0.12141153092802 +55,0.0000000000000004,-0.1627557440827222,0.0000000000000027,-0.08257 +98997978443,-0.0000000000000007,0.1886866183315523,-0.000000000000000 +9,-0.0554160985866513,-0.0000000000000009,-0.0016082286660558,0.00000 +00000000035,-0.1445886337968438,-0.0000000000000039,0.373441057958475 +9,0.0000000000000024,-0.5230941284069114,0.0000000000000000,0.5241670 +456105690,-0.0000000000000016,-0.3997788067656795,0.0000000000000018, +0.2084878025028327,-0.0000000000000011 ], [ -0.0000000000000000,0.0018740215138967,-0.0000000000000000,0.020914 +3122794822,-0.0000000000000002,0.0937250582686831,-0.0000000000000006 +,0.2263227689510601,-0.0000000000000010,0.2136068393701215,-0.0000000 +000000003,-0.0343030148937000,0.0000000000000006,-0.2374515116591406, +0.0000000000000009,0.1543298788071321,-0.0000000000000014,0.048410648 +8830808,0.0000000000000011,-0.0556695757276321,-0.0000000000000009,-0 +.1585122753165241,0.0000000000000015,0.4164529081832608,-0.0000000000 +000016,-0.5455319030422324,0.0000000000000021,0.4850082730133928,-0.0 +000000000000015,-0.2751494973249398 ], [ 0.0003983422749079,-0.0000000000000003,0.0084162036010590,-0.000000 +0000000008,0.0612865660082999,0.0000000000000003,0.2247020891769621,0 +.0000000000000001,0.4305239272210992,-0.0000000000000002,0.3202309758 +153931,0.0000000000000001,-0.1918139117119362,-0.0000000000000002,-0. +3095871293039516,-0.0000000000000002,0.2464518281395873,0.00000000000 +00006,0.1656482308020451,-0.0000000000000006,-0.3359183916702893,0.00 +00000000000000,0.1094739661795629,0.0000000000000012,0.24302905217495 +86,-0.0000000000000017,-0.4099538699310810,0.0000000000000015,0.29157 +77578643249,-0.0000000000000009 ], [ 0.0000000000000000,0.0014954639775851,0.0000000000000000,0.01796859 +65171856,0.0000000000000000,0.0988989956441026,0.0000000000000001,0.2 +952876521886211,0.0000000000000003,0.4627556007193223,0.0000000000000 +004,0.2320927274343102,0.0000000000000000,-0.2873578852921854,-0.0000 +000000000001,-0.2359945232765174,0.0000000000000001,0.311680124031071 +2,0.0000000000000003,0.0798333562246646,-0.0000000000000004,-0.341728 +8746164391,0.0000000000000003,0.1906004227513239,-0.0000000000000001, +0.1610665397841304,-0.0000000000000002,-0.3676708309232274,0.00000000 +00000002,0.2804853923818191 ], [ 0.0001084747877321,0.0000000000000000,0.0027208960217152,0.00000000 +00000002,0.0242704434475306,-0.0000000000000001,0.1153670170379691,-0 +.0000000000000005,0.3193789054222693,-0.0000000000000001,0.4908523839 +275092,0.0000000000000001,0.2761691414257316,0.0000000000000000,-0.26 +00143419201901,0.0000000000000001,-0.3068704363306086,-0.000000000000 +0002,0.2542843527027897,0.0000000000000000,0.2086903757180524,-0.0000 +000000000002,-0.3365315876512961,-0.0000000000000002,0.01653724898975 +50,0.0000000000000002,0.3099014215132993,-0.0000000000000001,-0.29551 +75636216057,0.0000000000000000 ], [ -0.0000000000000000,-0.0003844645253044,-0.0000000000000000,-0.0055 +700399702677,-0.0000000000000000,-0.0384100619532071,-0.0000000000000 +000,-0.1533025985895169,-0.0000000000000000,-0.3681698917672083,-0.00 +00000000000001,-0.4889286723129618,-0.0000000000000002,-0.19429626416 +19352,-0.0000000000000001,0.3158440934858354,-0.0000000000000001,0.24 +96900204706467,-0.0000000000000001,-0.2959512116085838,-0.00000000000 +00000,-0.1552508901502876,-0.0000000000000001,0.3427579648786467,-0.0 +000000000000002,-0.0541435546335990,0.0000000000000000,-0.28760313265 +88631,-0.0000000000000001,0.2927760031123848 ], [ 0.0000181563100889,0.0000000000000002,0.0005488425504935,-0.0000000 +000000000,0.0060688055327925,-0.0000000000000002,0.0372631786179999,- +0.0000000000000002,0.1425926143202678,-0.0000000000000000,0.347871001 +1662555,0.0000000000000002,0.5076314191518138,0.0000000000000006,0.31 +23574515561076,0.0000000000000001,-0.2091284023204721,-0.000000000000 +0002,-0.3689178831666572,-0.0000000000000000,0.1344053015043881,0.000 +0000000000001,0.3299092963194629,0.0000000000000004,-0.20822789510253 +15,-0.0000000000000003,-0.2240489250735314,-0.0000000000000001,0.3188 +632967650468,0.0000000000000002 ], [ -0.0000000000000000,0.0000646482239263,-0.0000000000000000,0.001138 +5375166878,-0.0000000000000000,0.0098338922987181,-0.0000000000000000 +,0.0513935599025939,-0.0000000000000001,0.1741934371091206,-0.0000000 +000000002,0.3836429445985159,-0.0000000000000004,0.5045604175490942,- +0.0000000000000004,0.2522551752686503,0.0000000000000001,-0.257944102 +5360375,0.0000000000000004,-0.3397702320139469,0.0000000000000003,0.1 +752821352580565,-0.0000000000000001,0.3071408379256653,0.000000000000 +0001,-0.2279977492913131,0.0000000000000002,-0.2051227648591225,-0.00 +00000000000004,0.3168989287342151 ], [ 0.0000019661699240,0.0000000000000002,0.0000719533317298,0.00000000 +00000001,0.0009846334801556,-0.0000000000000002,0.0077074332169402,-0 +.0000000000000004,0.0392493847315142,0.0000000000000002,0.13658602674 +96776,0.0000000000000000,0.3260488848298075,-0.0000000000000001,0.507 +5095625005354,0.0000000000000000,0.4189127624432365,-0.00000000000000 +03,-0.0412751650984030,-0.0000000000000002,-0.4061413387987063,0.0000 +000000000002,-0.1232820067450982,0.0000000000000001,0.352583981765542 +7,-0.0000000000000002,0.1125603524749182,-0.0000000000000002,-0.34863 +08267332468,0.0000000000000004 ], [ -0.0000000000000000,-0.0000071522511841,-0.0000000000000000,-0.0001 +531738843782,-0.0000000000000000,-0.0016457996800569,-0.0000000000000 +000,-0.0110351632854802,-0.0000000000000000,-0.0502042359369793,-0.00 +00000000000001,-0.1598827125229744,-0.0000000000000002,-0.35410559958 +16644,-0.0000000000000003,-0.5131002961113091,-0.0000000000000004,-0. +3827211429896542,-0.0000000000000001,0.0868953534697583,0.00000000000 +00002,0.4060663544932935,0.0000000000000002,0.0906849061585278,0.0000 +000000000001,-0.3565218256839784,0.0000000000000002,-0.09547988946696 +47,-0.0000000000000000,0.3460718461864576 ], [ -0.0000001292972631,-0.0000000000000001,-0.0000057407224638,0.00000 +00000000000,-0.0000969677496746,0.0000000000000000,-0.000957639115608 +1,-0.0000000000000002,-0.0063336604552633,0.0000000000000000,-0.02981 +94086989161,0.0000000000000001,-0.1025898937974792,0.0000000000000004 +,-0.2581306279126550,0.0000000000000004,-0.4608777058952639,0.0000000 +000000003,-0.5289025115880573,0.0000000000000000,-0.2501979027713430, +-0.0000000000000003,0.2459229288491326,-0.0000000000000000,0.39768907 +21949536,0.0000000000000001,-0.0441899989974140,-0.0000000000000001,- +0.3828591066315501,0.0000000000000001 ], [ 0.0000000000000000,0.0000004836289753,0.0000000000000000,0.00001259 +35691119,0.0000000000000000,0.0001674328686760,0.0000000000000000,0.0 +014204630187498,0.0000000000000000,0.0084233556059741,0.0000000000000 +000,0.0364726872642141,0.0000000000000000,0.1173353239240527,0.000000 +0000000001,0.2791623093846674,0.0000000000000001,0.4743110004921181,0 +.0000000000000002,0.5168194754141317,0.0000000000000002,0.21722128100 +95154,0.0000000000000001,-0.2660675030932704,0.0000000000000000,-0.38 +68615369372250,-0.0000000000000001,0.0582093189941330,0.0000000000000 +002,0.3792058820414961 ], [ 0.0000000043467313,-0.0000000000000002,0.0000002354338414,0.0000000 +000000001,0.0000049191205605,-0.0000000000000001,0.0000611103982443,0 +.0000000000000001,0.0005191484660093,0.0000000000000002,0.00322513771 +93584,-0.0000000000000002,0.0151840473609755,-0.0000000000000001,0.05 +51258405915315,0.0000000000000001,0.1547931322781031,0.00000000000000 +01,0.3318050095086971,-0.0000000000000004,0.5216362528850688,-0.00000 +00000000001,0.5386522451902931,-0.0000000000000004,0.2190409351878887 +,0.0000000000000002,-0.2724800121518238,0.0000000000000002,-0.4221250 +094454858,0.0000000000000001 ], [ -0.0000000000000000,-0.0000000167699136,-0.0000000000000000,-0.0000 +005331602679,-0.0000000000000000,-0.0000087760999773,-0.0000000000000 +000,-0.0000937543740401,-0.0000000000000000,-0.0007150017363018,-0.00 +00000000000000,-0.0040915831845336,-0.0000000000000000,-0.01805307191 +06190,-0.0000000000000000,-0.0621905012332527,-0.0000000000000000,-0. +1672502296997740,-0.0000000000000001,-0.3457819876105404,-0.000000000 +0000002,-0.5268406404622072,-0.0000000000000002,-0.5273801655434678,- +0.0000000000000002,-0.1998433947965230,0.0000000000000000,0.280500487 +4860440,0.0000000000000003,0.4170641909080779 ], [ 0.0000000000469012,0.0000000000000001,0.0000000031569888,-0.0000000 +000000001,0.0000000829508766,0.0000000000000000,0.0000013139183774,-0 +.0000000000000001,0.0000144662736142,0.0000000000000001,0.00011879541 +44757,-0.0000000000000001,0.0007576595856397,0.0000000000000002,0.003 +8457059058298,-0.0000000000000001,0.0157544770583618,0.00000000000000 +02,0.0524034914224598,-0.0000000000000002,0.1412730634268711,0.000000 +0000000000,0.3051191205191895,-0.0000000000000000,0.5135323458897670, +0.0000000000000002,0.6319248579965772,-0.0000000000000001,0.469989404 +2726668,-0.0000000000000000 ], [ -0.0000000000000000,0.0000000001872384,-0.0000000000000000,0.000000 +0073974097,-0.0000000000000000,0.0000001531161950,-0.0000000000000000 +,0.0000020854332860,-0.0000000000000000,0.0000206106783438,-0.0000000 +000000000,0.0001558996179038,-0.0000000000000000,0.0009318666076831,- +0.0000000000000000,0.0044889011562547,-0.0000000000000000,0.017620794 +6824076,-0.0000000000000000,0.0565953635430333,-0.0000000000000000,0. +1482728021860708,-0.0000000000000000,0.3129386149972143,-0.0000000000 +000000,0.5172629611893457,-0.0000000000000001,0.6280792712999990,-0.0 +000000000000001,0.4631473700646182 ] ]; #matrix T de los vectores del doblepozo my $vect= transpose($vec); #matrix con los vectores en la columna # <n|V|m> my $V= $vec x $X x $vect; my $step=0.1; my $hbar=1; #print &Vnm(0,1); #print&Vnm(1,0); my @Em=(-3.49090786,-3.48609059,-0.94249804,-0.72223315,0.84486159,1.9 +8334101,3.52168993,5.19562490,7.00900149,8.96758961,11.06144444445427 +60,13.1282317263938650,15.4597663541535190,18.2923955058715430,19.575 +1133106800170,21.3254642902799140,27.3060148356095880,33.615327480770 +2470,48.2864949409823790,58.1657460989797170,83.0782032408711330,97.3 +475523518670660,137.5307666823436800,157.3985331875067300,221.5161226 +004345300,248.6116702653141900,353.3740736965299900,390.0680354316574 +500,577.9792266930371600,628.4681868621187300); my $w=$Em[1]-$Em[0]; sub Vnm { my ($x1,$x2)=@_; return $V->range([$x1,$x2]); }; my $n; my $m; my $f; my @c = (1, 0, 0, 0); #INITIAL CONDITIONS #@c=F=(F0,F1,F2,F3) sub F0 { my ($t,@c)=@_; $m=0; $f=0; for ($n=0;$n<4;$n++){ my $a= &Vnm($n,$m)*exp(-(i)*($Em[$m]-$Em[$n])*($t/$hbar)); if ($n!=$m){ $f = $f + $a*(-(i)*(-$eprim)*cos($w*$t)*$c[$n]); }; }; return $f; }; sub F1 { my ($t,@c)=@_; $m=1; $f=0; for ($n=0;$n<4;$n++){ my $a= &Vnm($n,$m)*exp(-(i)*($Em[$m]-$Em[$n])*($t/$hbar)); if ($n!=$m){ $f = $f + $a*(-(i)*(-$eprim)*cos($w*$t)*$c[$n]); }; }; return $f; }; sub F2 { my ($t,@c)=@_; $m=2; $f=0; for ($n=0;$n<4;$n++){ my $a= &Vnm($n,$m)*exp(-(i)*($Em[$m]-$Em[$n])*($t/$hbar)); if ($n!=$m){ $f = $f + $a*-(i)*(-$eprim)*cos($w*$t)*$c[$n]; }; }; return $f; }; sub F3 { my ($t,@c)=@_; $m=3; $f=0; for ($n=0;$n<4;$n++){ my $a= &Vnm($n,$m)*exp(-(i)*($Em[$m]-$Em[$n])*($t/$hbar)); for ($n!=$m){ $f = $f +$a*(-(i)*(-$eprim)*cos($w*$t)*$c[$n]); }; }; return $f; }; #Método RK4 my $k1; my $k2; my $k3; my $k4; my $k1_1; my $k2_1; my $k3_1; my $k4_1; my $k1_2; my $k2_2; my $k3_2; my $k4_2; my $k1_3; my $k2_3; my $k3_3; my $k4_3; sub RK4_c0 { my ($t,@c)=@_; sub k1 { my ($t1,@c)=@_;return $step*&F0($t1,@c); }; sub k2 { my ($t2,@c)=@_;return $step*&F0(($t2+$step/2),( @c + (&k1($t2 +)/2)));}; sub k3 { my ($t3,@c)=@_;return $step*&F0(($t3+$step/2),( @c + (&k2($t3 +)/2))) ;}; sub k4 { my ($t4,@c)=@_;return $step*&F0(($t4+$step),( @c + &k3($t4))) +;}; return $c[0] + (1/6)*(&k1($t,@c)+ 2*(&k2($t,@c) + &k3($t,@c)) + &k4($ +t,@c)); }; sub RK4_c1 { my ($t,@c)=@_; sub k1_1 { my ($t1,@c)=@_;return $step*&F1($t1,@c); }; sub k2_1 { my ($t2,@c)=@_;return $step*&F1(($t2+$step/2),( @c + &k1($t +2/2)));}; sub k3_1 { my ($t3,@c)=@_;return $step*&F1(($t3+$step/2),( @c + &k2($t +3)/2)) ;}; sub k4_1 { my ($t4,@c)=@_;return $step*&F1(($t4+$step),( @c + &k3($t4) +));}; return $c[1] + (1/6)*(&k1_1($t,@c)+ 2*(&k2_1($t,@c) + &k3_1($t,@c)) + + &k4_1($t,@c)); }; sub RK4_c2 { my ($t,@c)=@_; sub k1_2 { my ($t1,@c)=@_;return $step*&F2($t1,@c); }; sub k2_2 { my ($t2,@c)=@_;return $step*&F2(($t2+$step/2),( @c + &k1($t +2)/2));}; sub k3_2 { my ($t3,@c)=@_;return $step*&F2(($t3+$step/2),( @c + &k2($t +3)/2)) ;}; sub k4_2 { my ($t4,@c)=@_;return $step*&F2(($t4+$step),( @c + &k3($t4) +));}; return $c[2] + (1/6)*(&k1_2($t,@c)+ 2*(&k2_2($t,@c) + &k3_2($t,@c)) + + &k4_2($t,@c)); }; sub RK4_c3 { my ($t,@c)=@_; sub k1_3 { my ($t1,@c)=@_;return $step*&F3($t1,@c); }; sub k2_3 { my ($t2,@c)=@_;return $step*&F3(($t2+$step/2),( @c + &k1($t +2)/2));}; sub k3_3 { my ($t3,@c)=@_;return $step*&F3(($t3+$step/2),( @c + &k2($t +3)/2)) ;}; sub k4_3 { my ($t4,@c)=@_;return $step*&F3(($t4+$step),( @c + &k3($t4) +));}; return $c[3] + (1/6)*(&k1_3($t,@c)+ 2*(&k2_3($t,@c) + &k3_3($t,@c)) + + &k4_3($t,@c)); }; my $t=0; open (FILE , ">C0_V1W01p2.dat"); for ($t=0; $t<2500;$t+=$step){ #print " @c $t \n"; #print abs($c[0])*abs($c[0]), "\n"; $c[0]= &RK4_c0($t,@c); $c[1]= &RK4_c1($t,@c); $c[2]= &RK4_c2($t,@c); $c[3]= &RK4_c3($t,@c); my $x= abs($c[0])**2; my $b= abs($c[1])**2; my $s= abs($c[2])**2; my $d= abs($c[3])**2; print FILE "$x $b $s $d $t\n"; }; close (FILE);
How Perl can push array into array and then how retrieve
3 direct replies — Read more / Contribute
by Anonymous Monk
on Nov 24, 2021 at 22:59
    How do we correctly push array into array and then retrieve each of the outer array (explain both each separately clearly) ?
    illustrated
    my @f; my @e; for $i (0..40) { @e=($i+=2, $i+1); push($f,@e); # just it right ? } # how go on get it under multi array control

    Please help out, very thanked in advance
Using system (); with Strawberry Perl
8 direct replies — Read more / Contribute
by hadrons
on Nov 24, 2021 at 18:50
    Hi, I'm a newbie here and this is my first question to the group, so forgive any lapse in etiquette. I wrote this script that is heavy in the use of system() and I run it using cygwin and it runs fine in that tool- however, when I use Strawberry Perl to run it there are a number of commands within the system() that it doesn't recognize. For example:
    system ('grep -l "DATAmessage.*3\.0" *.xml > 3.0_files_arraydata.txt') +; system ("mv temp_3.0_files_onixarraydata.txt 3.0_files_arraydata.txt") +; system ("cat *files_arraydata.txt > data2.txt"); system ("rm data2.txt"); system ("sort -u data2.txt > data.txt");
    It appears that the commands grep, mv, cat and rm all fail because "grep|mv|cat|rm is not recognized as an internal or external command, operation program or batch file" I also use sort, but I receive no error message for that command.

    I have tried other things to swap out the system calls like File::Grep in place of the grep calls, but while File::Grep works, it was slower than molasses in the dead of winter in Strawberry Perl. I know many look-down on the use of system ();, but I find it to be very fast. Any suggestions? And thank you for reading.


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":