Perl syntax errors on declaring a large constant array - perl

I want to declare a huge list of constant array like:
my #tlds = (ac ad ae aero af ag ai al am an ao aq ar arpa as asia at au aw ax az ba bb bd be bf bg bh bi biz bj bm bn bo br bs bt bv bw by bz ca cat cc cd cf cg ch ci ck cl cm cns
co com coop cr cu cv cw cx cy cz de dj dk dm do dz ec edu ee eg er es et eu fi fj fk fm fo fr ga gb gd ge gf gg gh gi gl gm gn gov gp gq gr gs gt gu gw gy hk hm hn hr ht hu id ie
il im in info int io iq ir is it je jm jo jobs jp ke kg kh ki km kn kp kr kw ky kz la lb lc li lk lr ls lt lu lv ly ma mc md me mg mh mil mk ml mm mn mo mobi mp mq mr ms mt mu museum mv mw mx my mz na name nc ne net nf ng ni nl no np nr nu nz om org pa pe pf pg ph pk pl pm pn pr pro ps pt pw py qa re ro rs ru rw sa sb sc sd se sg sh si sj sk sl sm sn so sr st su sv sx sy sz tc td tel tf tg th tj tk tl tm tn to tp tr travel tt tv tw tz ua ug uk us uy uz va vc ve vg vi vn vu wf ws xn xxx ye yt za zm zw);
But It throws errors:
1. Syntax error, near dm do dz
2. no such class mz, near "mw mx my mz"
ANy pointers on how to remove these errors?
If I use qw before that list it shows no errors, why? Whats wrong with the above declaration?

qw does quoting and separating for you.
my #foo = ( "bar", "baz" );
means the same as:
my #foo = qw( bar baz );
Having a stack of sequential unquoted values is just an error.
See the documentation for quote like operators.

The qw operator is a quoting operator, as are all of the other q* keywords (q qq qw qr qx) each takes a delimiting character (or pair in the case of braces) and treats everything within the delimiters as a string. Each of the operators do something different to the string, with qw splitting the string on whitespace to create a list.
When you write a series of barewords in Perl, you end up with a large nested chain of indirect object calls. Here is a short example without keywords (so that it is not a syntax error):
$ perl -MO=Deparse -e 'ac ad ae aero af ag ai al am an ao aq ar'
'ad'->ac('aero'->ae('ag'->af('al'->ai('an'->am('aq'->ao('ar'))))));
-e syntax OK
In your case, perl merrily went along parsing what looks like indirect object syntax until it encountered a keyword, which disrupted the chain and caused a syntax error.
If you had not used a keyword in your list, the code would have compiled fine, and then you would have gotten a runtime error about a missing method in a package. If you were running your code under the use strict; pragma (which you always should) then the final bareword would become a syntax error (since strict subs prevents promoting barewords to strings. That would have at least caught the error at compile time.
The important takeaway from this is that Perl has many quote-like operators that are effectively strings with special processing attached. Removing the quote-like operator will inevitably result in syntax errors, since arbitrarily formatted strings are not valid Perl. A list of the buitin quote-like operators can be found on the perlop manpage.

This is because when you omit qw/.../, your characters are treated as barewords, and when it comes to "do", which is a keyword, error is signaled.
EDIT: Even though my answer explains the reason of an error (well, I beleive so), #Quentin's suggestion is more constructive: do not use barewords (i.e. do use qw// in your example) to save your time catching errors like yours. For example, you have int in your list, which is also a keyword, lc (a function), etc.

Related

Writing numbers only each second and third line in Fortran

I am fighting with trying to get numbers 1 and 2 only on each second and third line in the second column.
I have a file tisk2 with
O
H
H
O
H
H
And I need to get to file tisk this:
O
H1
H2
O
H1
H2
I mean I want no number no text after O. I tried to write this code:
program cislo
implicit none
integer :: i, sum, j, k
character :: t*10, m*10
open(10,file="tisk2",status='old')
open(12,file="tisk",status='old')
do k=0,5
read(10,*) m
enddo
do j=1,3
do i = 0,0
t=" "
print*, t
exit
enddo
sum=0
do i=1,2
write(12,fmt='(a2,i2)') m, i
enddo
enddo
end program cislo
I can print only i and I get nothing, second line 1 and third line 2. Then alone print m. But when I want to put both to one file, it skips O and writes to file only H1, H2 and then again. Does anyone has an idea how to get what I need? Thank you for help.

Accessing external (DSPF) fields using arrays in RPGLE free

In the old RPG III and the non-free RPGLE/RPG IV you could "rename" fields you get from either a record of a PF/LF or a record from a DSPF.
This lead to possibilities like grouping several lines of input (additional order text) into a array. So I didn't have to MOVEL or EVAL ottxt1 to the external described field x1txt1, ottxt2 to x1txt2 and so on.
I'd only had to rename the LF record and the DSPF record fields to the array-fields, read the record and shift them from the one array to the other and display my DSPF record
H DECEDIT('0,') DATEDIT(*DMY.) dftactgrp(*no)
Fsls001 cf e workstn
Fordtxtl0 if e k disk
D ot s 20a dim(6)
D x1 s 20a dim(6)
Iordtxtr
I ottxt1 ot(1)
I ottxt2 ot(2)
I ottxt3 ot(3)
I ottxt4 ot(4)
I ottxt5 ot(5)
I ottxt6 ot(6)
Isls00101
I x1txt1 x1(1)
I x1txt2 x1(2)
I x1txt3 x1(3)
I x1txt4 x1(4)
I x1txt5 x1(5)
I x1txt6 x1(6)
C k$or00 klist
C kfld otonbr
C kfld otopos
C eval otonbr = 2
C eval otopos = 2
C k$or00 chain ordtxtr
C if %found(ordtxtl0)
C eval x1 = ot
C endif
C
C exfmt sls00101
C
C move *on *inlr
But is this also possible in *FREE RPGLE? And if so, how?
You can define data structures containing the fields from the files, and overlay them with an array.
Replace your I specs and array definitions with these data structures. You don't have to specify anything besides the field names for the fields from the externally-described file.
dcl-ds otDs;
ottxt1;
ottxt2;
ottxt3;
ottxt4;
ottxt5;
ottxt6;
ot like(ottxt1) dim(6) pos(1);
end-ds;
dcl-ds x1Ds;
x1txt1;
x1txt2;
x1txt3;
x1txt4;
x1txt5;
x1txt6;
x1 like(x1txt1) dim(6) pos(1);
end-ds;

Emacs auctex inserts line breaks after inline math in an ugly way

I got problems with emacs/auctex fill paragraph which insert linebreaks after each $blabla$ block, resulting in a poorly readable code. For exemple, hitting M-q on the following long line:
a $1$ b $2$ c $3$ d $4$ e $5$ f $6$ g $7$ h $8$ i $9$ j $10$ k $11$ l $12$ m $13$ n $14$ o $15$
Gives:
a $1$
b $2$
c $3$
d $4$
e $5$
f $6$ g $7$ h $8$ i $9$ j $10$ k $11$ l $12$ m $13$ n $14$ o $15$
I would like to have something like:
a $1$ b $2$ c $3$ d $4$ e $5$ f $6$ g $7$ h $8$ i $9$ j $10$ k
$11$ l $12$ m $13$ n $14$ o $15
Note: I have the impression that fill-paragraph didn't have this ugly behavior when I didn't use auctex but the built-in latex mode...
Any ideas?
Many thanks!
This can be fixed by changing the AUCTeX user option LaTeX-fill-break-at-separators (see AUCTeX Manual [Filling]).
Hit M-x and type customize-group in the minibuffer, then type LaTeX.
Now you should be able to see the option LaTeX Fill Break At Separators in the newly created buffer. Click on it (expanding it) and uncheck the box next to Closing Inline Math Switches. Don't forget to save.

Matlab: regexp usage

I am going to start illustration using a code:
A = 'G1(General G1Airlines american G1Fungus )';
Using regexp (or any other function) in Matlab I want to distinctively locate: G1, G1A and G1F.
Currently if I try to do something as:
B = regexp( A, 'G1')
It is not able to distinguish G1 with the G1A and G1F i.e. I need to force the comparison to find me only case with G1 and ignore G1A and G1F.
However, when I am searching for G1A then it should still find me the location of G1A.
Can someone please help ?
Edit: Another case for A is:
A = 'R1George Service SmalR1Al C&I)';
And the expression this time I need to find is R1 and R1A instead.
Edit:
I have a giant array containing A's and another big vector containing G1, R1, etc I need to search for.
If you want to find 'G1' but not 'G1A' or 'G1F' you can use
>> B = regexp(A, 'G1[^AF]')
B =
1
This will find 'G1' and the ^ is used to specify that it should not match any characters contained with []. Then you could use
>> B = regexp(A, 'G1[AF]')
B =
12 32
to find both 'G1A' and 'G1F'.

Matlab switch-case issue

I got a strange issue when i try to run a multiple switch-case ( 6 concatened switch-case, from 2 to 11 choices, char choices).
the inputs for the m. file with the swith case come from a GUI with 6 buttongroup and radiobutton, but i guess this is not the problem.
In fact, the problem is that if i pass the values "manually", kinda:
evaluation= Holdem_Postflop_Decision_Tree('midv','rn','fd', 'oop', 'hu',25)
i got to the right solution, that is simply a string ( ideally, this will return to the GUI and will be replace in an EDIT-TEXT box):
evaluation =
bettiamo perchè oop e calla abb spesso per floatare.
Al turn decidiamo di c/c o c/r su blank in base alla size, se cade suited c/f.
se turn abbiamo c/c e river è blank siamo in modalità vita c/c bottom-mid case: cbetptkiamo perchè oop.
Se raisa foldiamo.
Instead, if i do
evaluation= Holdem_Postflop_Decision_Tree(handles.val, handles.act, handles.text, handles.pos, handles.num, handles.bb);
and
handles.val='midv';
handles.act='rn';
handles.text='fd';
handles.pos='oop';
handles.num='hu';
handles.bb=25;
i get this error
??? Undefined function or variable "evaluation".
Error in ==> Holdem_Postflop_Decision_Tree at 6998
Moreover, if i create a Main.m like so:
value= input (' Value', 's');
action=input(' Action: ','s');
texture= input (' Texture', 's');
pos=input(' Position: ','s');
num= input (' Opponumber', 's');
bb=input(' Big blinds: ');
evaluation= Holdem_Postflop_Decision_Tree(value, action, texture, pos, num,bb);
it does work!
I really dont get it: what's the difference? I checked that all handles.field are char, and if not, i've placed at the very beginning this:
value=char(value);
actionpre=char(actionpre);
texture=char(texture);
pos=char(pos);
opponumber=char(opponumber);
I thought it was a multiple switch case problem, because if i enter the Holdem_Postflop_Decision_Tree.m from the GUI and i make separate switch-case, Matlab runs it, while it stops at the third, but now i cant think it's a multiple s-c problem, since if i put the value manually it goes through it without problem.
Any help?
P.S: i'll add the code for the string above:
case 'midv'
switch actionpre
case 'rn'
switch texture
case 'fd'
switch pos
case 'ip'
switch opponumber
case 'hu'
evaluation=' No info yet.';
case 'multiway'
evaluation=' No info yet.';
end
case 'oop'
switch opponumber
case 'hu'
if bb>15
evaluation='Cbettiamo perchè oop e calla abb spesso per floatare. Al turn decidiamo di c/c o c/r su blank in base alla size, se cade suited c/f.se turn abbiamo c/c e river è blank siamo in modalità vita c/c bottom-mid case: cbetptkiamo perchè oop. Se raisa foldiamo. Al turn se non improviamo siamo sempre in c/f a meno di info che non foldi spesso alla 2barrel, in quel caso possiamo betptkare, se calla e non improviamo river o turn è suited siamo in c/f river';
else
evaluation='cbettiamo per brokare';
end
case 'multiway'
evaluation=' No info yet.';
end