Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
tutorial:perl_continued [2011/05/09 14:47] – extended continuative perl tutorial herr | tutorial:perl_continued [2017/07/26 14:44] (current) – fused with perl_intro oroehrig | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | [[tutorial: | ||
- | ===Standard data structures=== | ||
- | The Perl programming language originally provides three different data structures, scalars($), arrays(@), and hashes(%). The user always has to specify the type of a variable using the appropriate symbol '' | ||
- | < | ||
- | polytope > i=5; | ||
- | polymake: | ||
- | </ | ||
- | Here are some simple commands illustrating how to use the different data structures: | ||
- | * **Scalars** < | ||
- | $i=5; | ||
- | $j=6; | ||
- | $sum=$i+$j; print $sum; | ||
- | </ | ||
- | * **Arrays** < | ||
- | @array=(" | ||
- | push(@array," | ||
- | $first_entry=$array[0]; | ||
- | print join(" | ||
- | @array2=(3, | ||
- | print sort(@array2); | ||
- | </ | ||
- | * **Hashes** < | ||
- | %hash=(); | ||
- | $hash{" | ||
- | $hash{" | ||
- | print keys %hash; | ||
- | print join(", | ||
- | print join(", | ||
- | %hash=(" | ||
- | %hash=(" | ||
- | </ | ||
- | ===" | ||
- | < | ||
- | $arr1=new Array< | ||
- | $arr2=new Array< | ||
- | $arr3=new Array< | ||
- | $arr4=new Array< | ||
- | @arr4=@{$arr4}; | ||
- | print $arr2; | ||
- | $set=new Set< | ||
- | $mat=new Matrix< | ||
- | $mat-> | ||
- | $mat-> | ||
- | print 4*unit_matrix< | ||
- | $m_rat=new Matrix< | ||
- | $m2=$mat/ | ||
- | $m_int=new Matrix< | ||
- | $m3=$m_rat/ | ||
- | $m3=$m_rat/ | ||
- | $z_vec=zero_vector< | ||
- | $extended_matrix=($z_vec|$m_int); | ||
- | $template_Ex=new Array< | ||
- | $template_Ex; | ||
- | </ | ||
- | ===" | ||
- | < | ||
- | $p=new Polytope< | ||
- | $lp=new LinearProgram< | ||
- | $p-> | ||
- | print $p-> | ||
- | </ | ||
- | ===Working with Perl in polymake=== | ||
- | {{: | ||
- | < | ||
- | open(INPUT, "< / | ||
- | $matrix=new Matrix< | ||
- | close(INPUT); | ||
- | print $matrix; | ||
- | |||
- | $p=new Polytope< | ||
- | print $p-> | ||
- | print $p->DIM; | ||
- | print $p-> | ||
- | ;### choose " | ||
- | for(my $i=0; | ||
- | if($p-> | ||
- | print $i.": " | ||
- | } | ||
- | } | ||
- | $s=new Set< | ||
- | for(my $i=0; | ||
- | if($p-> | ||
- | $s+=$i; | ||
- | } | ||
- | } | ||
- | $special_points=$p-> | ||
- | ; | ||
- | foreach(@{$s}){ | ||
- | print $p-> | ||
- | } | ||
- | foreach my $index(@{$s}){ | ||
- | print $p-> | ||
- | } | ||
- | </ | ||
- | |||
- | ===Scripts=== | ||
- | [[scripting: |